commit aa930c1180f13b6fdba2b378fc1f8e7675f53f95
parent 75da160c2d510c934e6d8c24c542e3e3edaf5e9e
Author: Stephen Chang <stchang@ccs.neu.edu>
Date: Thu, 17 Dec 2015 17:05:25 -0500
add more infer examples
Diffstat:
1 file changed, 9 insertions(+), 0 deletions(-)
diff --git a/tapl/tests/infer-tests.rkt b/tapl/tests/infer-tests.rkt
@@ -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}))