
18 Oct
2009
18 Oct
'09
5:43 p.m.
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.