[Haskell-cafe] ((a -> b) -> c) -> (a -> m b) -> m c

Henning Thielemann lemming at henning-thielemann.de
Sun Sep 9 06:12:11 EDT 2007


On Sun, 9 Sep 2007, Stuart Cook wrote:

> (Inspired by this[1] reddit thread.)
>
> When combining monadic and non-monadic code, I've often wished for a
> magical combinator of type
>
>  (Monad m) => ((a -> b) -> c) -> (a -> m b) -> m c
>
> which would let me inject a monadic function into a pure one, then
> wrap the ultimate result to ensure that no nastiness escapes.

If the signature would be
   (Monad m) => ((a -> b) -> c) -> m (a -> b) -> m c
    it would be possible, and the implementation would be 'liftM'/'fmap'.

In the Reader monad you can even convert
   (a -> m b)   to   m (a -> b)


More information about the Haskell-Cafe mailing list