+(test (data-tors '(A . ((foo Int Bool)
+ (bar Bool))))
+ '((foo . (constructor . (abs Int (abs Bool A))))
+ (foo~0 . (0 . (abs A Int)))
+ (foo~1 . (1 . (abs A Bool)))
+ (bar . (constructor . (abs Bool A)))
+ (bar~0 . (0 . (
+
+ abs A Bool)))))
+
+(test (data-tors-env
+ '(A . ((foo Int Bool)
+ (bar Bool))))
+ '((foo . (abs Int (abs Bool A)))
+ (foo~0 . (abs A Int))
+ (foo~1 . (abs A Bool))
+ (bar . (abs Bool A))
+ (bar~0 . (abs A Bool))))
+
+(test-types (typecheck '((lambda (x) (+ ((lambda (y) (x y 3)) 5) 2))))
+ '(abs (abs Int (abs Int Int)) Int))
+
+ ; recursive types
+
+(test-types (substitute '((t1 . (abs t1 t10))) 't1) '(abs t1 t10))
+
+(test-types (typecheck '((let ([bar (lambda (y) y)]
+ [foo (lambda (x) (foo (bar #t)))])
+ foo)))
+ '(abs Bool a))
+
+(test-types (typecheck '((let ([bar (lambda (y) y)]
+ [foo (lambda (x) (foo (bar #t)))])
+ bar)))
+ '(abs a a))
+
+(test-types (typecheck '((let ([foo 3]
+ [bar (+ foo baz)]
+ [baz (- bar 1)])
+ bar)))
+ 'Int)
+
+(test-types (typecheck '((let ([foo 3]
+ [bar (baz foo)]
+ [baz (lambda (x) x)])
+ baz)))
+ '(abs a a))
+
+(test-types (typecheck '((let ([foo 3]
+ [bar (baz foo)]
+ [baz (lambda (x) x)])
+ bar)))
+ 'Int)
+
+ ; mutual recursion
+(test-types (typecheck '((let ([f (lambda (n) (if (= n 0)
+ 0
+ (+ 1 (g (- n 1)))))]
+ [g (lambda (m) (f m))])
+ (f 10))))
+ 'Int)
+
+(test-types (typecheck '((let ([pow (lambda (p y)
+ (let ([go (lambda (n x)
+ (if (= n 0)
+ x
+ (go (- n 1) (* x y))))])
+ (go p 1)))])
+ (pow 4 2))))
+ 'Int)
+
+ ; ADTs