[Haskell-beginners] count function

Felipe Lessa felipe.lessa at gmail.com
Sun Oct 18 13:43:00 EDT 2009


On Sun, Oct 18, 2009 at 06:51:41PM +0200, Daniel Fischer wrote:
> fileLines str = readFile str >>= return . length . lines

This kind of construction requires a Monad, which is a lot of power.

> fmap (length . lines) (readFile str)

On the other hand, this only requires a Functor.  Yes, in this
particular case the type is going to be IO anyway, but 'fmap'
should be used instead of '>>= return .'.

--
Felipe.


More information about the Beginners mailing list