Monads, again :)

57 views
Skip to first unread message

Leonardo Borges

unread,
Apr 28, 2015, 10:44:19 PM4/28/15
to clojure-c...@googlegroups.com
Digging through the source code of core.typed I found a namespace that guided me through successfully type checking the following:

  (t/cf (t/defalias MonadLB
          (t/TFn [[x :variance :covariant]] t/Nothing)))

  (t/cf (t/defprotocol [[M :variance :covariant,
                         :> MonadLB
                         :< Monad]]
          Monad
          ([a] return [mv :- (M a) v :- a] :- (M a))
          ([a b] bind [mv :- (M a) f :- [a -> (M b)]] :- (M b))))


Which seems reasonable. However, when I then try to type check a function that depends on this information, I get the error: 

"Type Error:  Internal Error: Lower-bound MonadLB is not below upper-bound Monad"


The offending function definition and annotation are as follows:

  (t/cf (ann  for-all-m (All [[f :< Monad] a]
                             [(f Boolean)
                              [a -> (f Boolean)]
                              (Option a)
                              -> (f Boolean)])))

  (t/cf (defn for-all-m [ctx p o]
          ((inst return f Boolean) ctx false)))

Thoughts?

Cheers

Ambrose Bonnaire-Sergeant

unread,
Apr 28, 2015, 11:00:07 PM4/28/15
to core.typed
What happens if you omit the lower bound?

It's dumb that you have to provide it, but I remember why I now.

Thanks,
Ambrose

Leonardo Borges

unread,
Apr 28, 2015, 11:45:09 PM4/28/15
to core.typed
Do you mean in the protocol definition like so?


(t/cf (t/defprotocol [[M :variance :covariant,
                         :< Monad]]
          Monad
          ([a]   return [mv :- (M a) v :- a]            :- (M a))
          ([a b] bind   [mv :- (M a) f :- [a -> (M b)]] :- (M b))))

This errors with:

Type Error : Internal Error : Could not resolve Protocol: myns.core/Monad


Reply all
Reply to author
Forward
0 new messages