37 lines
989 B
Racket
37 lines
989 B
Racket
#lang typed/racket
|
|
(require "../typed-parser.rkt")
|
|
(require typed/rackunit)
|
|
|
|
(test-begin
|
|
(check-equal? (parse-from-string
|
|
#<<END
|
|
I x = x ;
|
|
K x y = x ;
|
|
K1 x y = y ;
|
|
S f g x = f x (g x) ;
|
|
compose f g x = f (g x) ;
|
|
twice f = compose f f ;
|
|
Q x = Pack {3 , 1 } x ;
|
|
P x = case x of
|
|
<1> -> 0 ;
|
|
<2> x -> 1 + P x
|
|
END
|
|
)
|
|
'((define (I x) x)
|
|
(define (K x y) x)
|
|
(define (K1 x y) y)
|
|
(define (S f g x) ((f x) (g x)))
|
|
(define (compose f g x) (f (g x)))
|
|
(define (twice f) ((compose f) f))
|
|
(define (Q x) ((pack 3 1) x))
|
|
(define (P x) (case x ((1 () 0) (2 (x) ((+ 1) (P x))))))))
|
|
(check-equal? (parse-from-string
|
|
#<<END
|
|
foo o = let x = 4 ;
|
|
y = let z = 3 ;
|
|
k = 4 in k + z in
|
|
x + y + o
|
|
END
|
|
) '((define (foo o)
|
|
(let ((x 4)(y (let ((z 3)(k 4)) ((+ k) z))))
|
|
((+ ((+ x) y)) o))))))
|