
Henning Thielemann wrote:
On Sun, 9 Sep 2007, Stuart Cook wrote:
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)
The existence of a conversion convert :: (a -> m b) -> m (a -> b) between those two types for a given monad m is equivalent to the existence of magic :: ((a -> b) -> c) -> (a -> m b) -> m c since we have convert = magic id magic f g = return f `ap` convert g Regards, apfelmus