test-poly.rkt (3546B)
1 #lang typed/racket 2 3 (define-syntax (skip<6.3 stx) 4 (syntax-case stx () 5 [(_ . rest) 6 (if (or (regexp-match #px"^6(\\.[012](\\..*|)|)$" (version)) 7 (regexp-match #px"^[123245]\\..*$" (version))) 8 #'(begin) 9 #'(begin . rest))])) 10 11 (require typed-struct-props 12 typed/rackunit) 13 14 (skip<6.3 15 (struct/props (A) foo1 ([f : A] [g : A]) #:transparent 16 #:property prop:custom-write 17 (λ (this out mode) 18 (write (ann (list (foo1-f this) 19 (foo1-g this)) 20 (Listof A)) 21 out)))) 22 23 (skip<6.3 24 (struct/props (A) foo2 ([f : A] [g : A]) #:transparent 25 #:property prop:equal+hash 26 (list (λ (a b rec) 27 ;; We can access the A ... here, but not the A' ... 28 (ann (list (foo2-f a) 29 (foo2-g a)) 30 (Listof A)) 31 #f) 32 (λ (a rec) 33 ;; Type inference works, despite the lambda being in a 34 ;; list, because we detect the special case where a list 35 ;; is immediately constructed. 36 (ann (list (foo2-f a) 37 (foo2-g a)) 38 (Listof A)) 39 42) 40 (λ (a rec) 41 ;; Type inference works, despite the lambda being in a 42 ;; list, because we detect the special case where a list 43 ;; is immediately constructed. 44 (ann (list (foo2-f a) 45 (foo2-g a)) 46 (Listof A)) 47 43)))) 48 49 (struct/props (A) foo3 ([f : A] [g : A]) #:transparent 50 #:property prop:custom-write 51 (λ #:∀ (X) ([this : (foo3 X)] out mode) 52 (write (ann (list (foo3-f this) 53 (foo3-g this)) 54 (Listof X)) 55 out))) 56 57 (struct/props (A) foo4 ([f : A] [g : A]) #:transparent 58 #:property prop:equal+hash 59 (list (λ #:∀ (Y YY) ([a : (foo4 Y)] [b : (foo4 YY)] rec) 60 ;; We can access the A ... here, but not the A' ... 61 (ann (list (foo4-f a) 62 (foo4-g a)) 63 (Listof Y)) 64 (ann (list (foo4-f b) 65 (foo4-g b)) 66 (Listof YY)) 67 #f) 68 (λ #:∀ (Z) ([a : (foo4 Z)] rec) 69 ;; Type inference works, despite the lambda being in a 70 ;; list, because we detect the special case where a list 71 ;; is immediately constructed. 72 (ann (list (foo4-f a) 73 (foo4-g a)) 74 (Listof Z)) 75 42) 76 (λ #:∀ (W) ([a : (foo4 W)] rec) 77 ;; Type inference works, despite the lambda being in a 78 ;; list, because we detect the special case where a list 79 ;; is immediately constructed. 80 (ann (list (foo4-f a) 81 (foo4-g a)) 82 (Listof W)) 83 43))) 84 85 ;; TODO: write some negative tests.