[Haskell-cafe] Can we come out of a monad?
Stefan Holdermans
stefan at vectorfabrics.com
Sat Jul 31 01:48:15 EDT 2010
Alexey,
>>> There is one case where you can break out of a monad without knowing which
>>> monad it is. Well, kind of. It's cheating in a way because it does force
>>> the use of the Identity monad. Even if it's cheating, it's still very
>>> clever and interesting.
>>
>> How is this cheating? Or better, how is this breaking out of a monad "without
>> knowing which monad it is"? It isn't. You know exactly which monad you're
>> breaking out: it's the identity monad. That's what happens if you put
>> quantifiers in negative positions: here, you are not escaping out of an
>> arbitrary monad (which you can't), but escaping out of a very specific monad.
>>
> No I think here we breaking out from _arbitrary_ monad. If monadic
> function works for every monad then it must work for identity monad
> too.
Once, again: no. :) You're not escaping from an arbitrary monad; you are escaping from the identity monad.
>> purify2 :: (forall m . Monad m => m a) -> a
>> purify2 m = runIdentity m
The function you pass into purify2 works for an arbitrary monad. Purify itself instantiates this function to the identify monad—and then escapes from it.
My former boss used to tell me that these are the kinds of things you should try to explain yourself while riding you're bike. If longer you ride your bike, the better you'll understand it.
Have fun biking ;-),
Stefan
More information about the Haskell-Cafe
mailing list