Strange behavior with a mapping-function

15 views
Skip to first unread message

mat...@flow.net

unread,
Oct 22, 2015, 5:28:47 PM10/22/15
to core.typed
Hey Ambrose,

The following is giving me trouble:

(defalias Pair '[String String])

(ann get-second-fails [(t/Vec Pair) -> (t/Seqable String)])
(defn get-second-fails [in]
  (map second in))

(ann get-second-works [(t/Vec Pair) -> (t/Seqable String)])
(defn get-second-works [in]
  (map (t/fn [i :- Pair] (second i)) in))

In a nutshell, passing the second function directly to map doesn't work - I have to wrap it in the core.typed function macro.

What's up with that?

Cheers.

(error is:

Type Error (rest_api/types.clj:459:3) Polymorphic function map could not be applied to arguments:
Polymorphic Variables:
c
a
b

Domains:
[a b ... b -> c] (t/NonEmptySeqable a) (t/NonEmptySeqable b) ... b
[a b ... b -> c] (t/U (Seqable a) nil) (t/U (Seqable b) nil) ... b

Arguments:
(t/All [x] (t/IFn [(t/HSequential [t/Any x t/Any *]) -> x :object {:id 0, :path [(Nth 1)]}] [(t/Option (t/I (t/CountRange 0 1) (Seqable x))) -> nil] [(t/I (t/CountRange 2) (Seqable x)) -> x] [(t/Option (Seqable x)) -> (t/Option x)])) (IPersistentVector Pair)

Ranges:
(t/NonEmptyASeq c)
(t/ASeq c)

with expected type:
(t/Seqable String)


in: (map second in)

Ambrose Bonnaire-Sergeant

unread,
Oct 22, 2015, 9:52:41 PM10/22/15
to core.typed
Hi Matthew,

Polymorphic arguments to polymorphic functions must be instantiated. See this blog.

Something like (map (inst second String) in) should work.

Thanks,
Ambrose
Reply all
Reply to author
Forward
0 new messages