[Haskell-cafe] Can we come out of a monad?
Jason Dagit
dagit at codersbase.com
Fri Jul 30 13:54:30 EDT 2010
On Fri, Jul 30, 2010 at 12:29 AM, Stefan Holdermans <
stefan at vectorfabrics.com> wrote:
> Jason,
>
> > 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.
>
> > The specific function is:
> > > purify :: (forall m. Monad m => ((a -> m b) -> m b)) ->
> ((a->b)->b)
> > > purify f = \k -> runIdentity (f (return . k))
>
I guess I refer to it as cheating because the type signature of purify is
surprising the first time you see it, even if perfectly logical.
Jason
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100730/77f84235/attachment.html
More information about the Haskell-Cafe
mailing list