Fork me on GitHub
#core-typed
<
2023-10-06
>
Corneliu Hoffman09:10:59

Hi, Rather newbie here Working my way through typed closure trying to build a small typed DSL. Wondering about the use of t/Merge. It seems to not work with polymorphic types. I kind of expected to be able to define:

(t/ann mapmerge (t/All [a b] [ a [a -> b] -> (t/Merge a b)]))
(defn mapmerge [a f] (merge a (f a)))
I get
No implementation of method: :fold-default* of protocol: #'typed.cljc.checker.fold-rep/IFoldDefault found for class: typed.cljc.checker.type_rep.MergeType
Is a variation of this possible? It seems that if a or b are not maps presumably t/Merge seems to revert to t/Any so presumably this is safe. I can write a macro of course but I was hoping for a more out-of-the-box solution :)

ambrosebs19:10:02

I think this was fixed in 1.1.0 or 1.1.3. Are you using the latest version?

ambrosebs20:10:30

Well, the error is fixed, but the inference doesn't work. I'll try and fix it.

ambrosebs20:10:02

fixed it, will push a new version

ambrosebs20:10:03

You'll need to use bounded type variables to get it to work:

(t/All [[a :< (t/Nilable (t/Map t/Any t/Any))]
        [b :< (t/Nilable (t/Map t/Any t/Any))]]
       [a [a :-> b] :-> (t/Merge a b)])

ambrosebs22:10:11

released 1.1.4 with this fix