[Haskell-cafe] Re: walking a directory tree efficiently

Luke Palmer lrpalmer at gmail.com
Wed Jan 14 19:52:38 EST 2009

On Wed, Jan 14, 2009 at 5:04 PM, Paolo Losi <paolo at hypersonic.it> wrote:

> 2) I have written some support functions: mapM' and filterM'
>>   Are they well written and generic?
> mapM' is generic and already implemented: fmap
> (Note that a Monad is also a Functor)

Except for when it isn't, which is really annoying because it ought to be.
I just pretend it is, and then grit my teeth and kill a baby when I get

And mapM' is not fmap, but fmap.fmap (or liftM.map if you prefer).

> filterM' is specific enough not to deserve any package
> filterM' = fmap . map

Uh, I think you're looking at the wrong one.

filterM' :: (a -> m Bool) -> m [a] -> m [a]

I would write this as:

filterM' p = filterM p . return

And then probably just go inline it.

> that I like more...
>    Are they already available in some package?
>>   Can you suggest better names?
>> 3) I find
>>   (,) node `liftM` walkTree' path
>>   not very readable.
>>   Is it possible to express it in a more (not too much) verbose way?
> I find it readable... It's ok IMO.

A bit ugly, perhaps. With the notation from Control.Applicative:

(,) node <$> walkTree' path

I would really like to be able to do a proper-looking tuple section though;

(node,) <$> walkTree' path

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090114/98f7020a/attachment.htm

More information about the Haskell-Cafe mailing list