Skip to content

Instantly share code, notes, and snippets.

@mpenet
Last active December 15, 2015 01:09
Show Gist options
  • Save mpenet/5178149 to your computer and use it in GitHub Desktop.
Save mpenet/5178149 to your computer and use it in GitHub Desktop.
(defn foo [x] (apply str x))
(ann foo [(U (Vector* String)
(Seq* String)
(List* String))
-> String])
user> (cf (foo ["a" "b"]))
>> java.lang.String
user> (cf (foo (seq ["a" "b"])))
Exception Type Error, NO_SOURCE_FILE:1
Actual type
(clojure.core.typed/Option (I (clojure.lang.ISeq (U (Value "a") (Value "b"))) (CountRange 1)))
is not a subtype of Expected type
(U [java.lang.String] (Seq* java.lang.String) (List* java.lang.String)) clojure.core.typed/type-error (subtype.clj:24)
user> (cf (foo (list "a" "b")))
Exception Type Error, NO_SOURCE_FILE:1
Actual type
(clojure.lang.PersistentList (U (Value "a") (Value "b")))
is not a subtype of Expected type
(U [java.lang.String] (Seq* java.lang.String) (List* java.lang.String)) clojure.core.typed/type-error (subtype.clj:24)
;; My goal was to define a TFn as follows
(t/def-alias Sequential* (TFn [[x :variance :covariant]]
(U (Vector* x)
(List* x)
(Seq* x))))
;; I tried getting inspiration from https://github.com/clojure/core.typed/blob/master/src/main/clojure/clojure/core/typed/ann.clj
;; From what I can see maybe Seqable is what I should be doing instead of all that. But I couldn't get it to work/load
(ann foo [(Seqable String)  -> String])
Exception Cannot parse list: (Seqable String)  clojure.core.typed/eval10041/fn--10043 (parse.clj:363)
;; adding ISeq to my crazy (and likely wrong) Sequantial* did the trick for (seq [..]) but it still not perfect.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment