cur/nat.rkt
William J. Bowman c24650ef01 Started work to enable reflection
* sigma, gamma extended at expand time
* All type-checking happens at expand time
* Locally expand all forms into core redex forms. However, this seems to
  be causing problems. Probably not controlling expansion just right.
2015-01-27 23:55:50 -05:00

35 lines
738 B
Racket

#lang s-exp "cur-redex.rkt"
(require "sugar.rkt")
(module+ test
(require rackunit))
(data nat : Type
(z : nat)
(s : (-> nat nat)))
(define (add1 (n : nat)) (s n))
(module+ test
(check-equal? (add1 (s z)) (s (s z))))
(define (sub1 (n : nat))
(case n
[z z]
[s (lambda (x : nat) x)]))
(module+ test
;; TODO: Um. For some reason, sigma becomes empty here?
(check-equal? (sub1 (s z)) z))
(define plus
(fix (plus : (forall* (n1 : nat) (n2 : nat) nat))
(lambda (n1 : nat)
(lambda (n2 : nat)
(case n1
[z n2]
[s (λ (x : nat) (plus x (s n2)))])))))
(module+ test
(check-equal? (plus z z) z)
(check-equal? (plus (s (s z)) (s (s z))) (s (s (s (s z))))))
(add1 (s z))
(sub1 (s z))