[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:44:37 EDT 2005


> There is no inherent advantage or disadvantage
> to monads. If the idea is most clearly expressed
> as a monad, use a monad. If the idea is most
> clearly expressed recursively, write it recursively
> (but perhaps wrap it in "return").

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