add more infer examples

This commit is contained in:
Stephen Chang 2015-12-17 17:05:25 -05:00
parent 75da160c2d
commit aa930c1180

View File

@ -44,6 +44,8 @@
(define {X} (g3 [lst : (List X)] X) (hd lst))
(check-type g3 : ( {X} (List X) X))
(check-type g3 : ( {A} (List A) A))
(check-not-type g3 : ( {A B} (List A) B))
(typecheck-fail (g3) #:with-msg "Expected.+arguments with type.+List") ; TODO: more precise err msg
(check-type (g3 (nil {Int})) : Int) ; runtime fail
(check-type (g3 (nil {Bool})) : Bool) ; runtime fail
@ -74,6 +76,12 @@
; recursive call should instantiate to "concrete" X and Y types
(cons (f (hd lst)) (map f (tl lst)))))
(check-type map : ( {X Y} ( X Y) (List X) (List Y)))
(check-type map : ( {Y X} ( Y X) (List Y) (List X)))
(check-type map : ( {A B} ( A B) (List A) (List B)))
(check-not-type map : ( {X Y} ( X X) (List X) (List X)))
(check-not-type map : ( {X} ( X X) (List X) (List X)))
; nil without annotation tests fn-first, left-to-right arg inference (2nd #%app case)
(check-type (map add1 nil) : (List Int) (nil {Int}))
(check-type (map add1 (list)) : (List Int) (nil {Int}))
@ -169,6 +177,7 @@
nil
(hd solns)))))
(check-type nqueens : ( Int (List Queen)))
(check-type (nqueens 1) : (List Queen) (list (list 1 1)))
(check-type (nqueens 2) : (List Queen) (nil {Queen}))
(check-type (nqueens 3) : (List Queen) (nil {Queen}))