Created
August 10, 2012 13:52
-
-
Save frenchy64/3314344 to your computer and use it in GitHub Desktop.
F-bounded Polymorphism in Typed Clojure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; y has upper bound x, z has upper bound (Seqable y) | |
typed.core=> (ann foo (All [x [y :< x] [z :< (Seqable y)]] | |
[x y z -> Any])) | |
[typed.core/foo (All [x [y :< x] [z :< (clojure.lang.Seqable y)]] (Fn [x y z -> Any]))] | |
typed.core=> (declare foo) | |
#'typed.core/foo | |
;cf = check-form | |
typed.core=> (cf (foo 2 2 [2])) | |
Any | |
typed.core=> (cf (foo 2 2 [1])) | |
#<AssertionError java.lang.AssertionError: Assert failed: Inferred type (Vector* (Value 1)) is not between bounds Nothing and (clojure.lang.Seqable (Value 2)) | |
(and (subtype? inferred upper-bound) (subtype? lower-bound inferred))> | |
typed.core=> (cf (foo 2 1 [2])) | |
#<AssertionError java.lang.AssertionError: Assert failed: Inferred type (Vector* (Value 2)) is not between bounds Nothing and (clojure.lang.Seqable (Value 1)) | |
(and (subtype? inferred upper-bound) (subtype? lower-bound inferred))> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment