[Haskell-cafe] Monadic vs "pure" style (was: pros and cons of sta tic typing and side effects)

Ben Lippmeier Ben.Lippmeier at anu.edu.au
Tue Aug 30 20:55:29 EDT 2005


Perhaps you could write _everything_ in monadic style, and then derive 
the non-monadic version by running it on an "empty" state monad. But 
then if everything was already monadic you wouldn't need the non-monadic 
version..  :)

...

> Perhaps the "inherent disadvantage" is that functions written in the 
> monadic style must have different types compared with their conceptually 
> similar non-monadic functions..
> 
> mapM    :: Monad m => (a -> m b) -> [a] -> m [b]
> map     :: (a -> b) -> [a] -> [b]
> 
> filter  :: (a -> Bool) -> [a] -> [a]
> filterM :: (Monad m) => (a -> m Bool) -> [a] -> m [a]
> 
> foldl   :: (a -> b -> a) -> a -> [b] -> a
> foldM   :: (Monad m) => (a -> b -> m a) -> a -> [b] -> m a
> 
> Some would say "but they're different functions!", others would say 
> "close enough".
> 
> I imagine this would be an absolute pain for library writers. Notice 
> that we get Data.Map.map but no Data.Map.mapM - or perhaps there's some 
> magical lifting combinator that I am not aware of?
> 
> Ben.


More information about the Haskell-Cafe mailing list