[Haskell-cafe] Name that function =)

Louis J Scoras louis.j.scoras at gmail.com
Tue Dec 12 19:28:34 EST 2006


On 12/12/06, Conal Elliott <conal at conal.net> wrote:
> This rewrite changes the order of execution.  The old version did all of the
> putDirs and then all of the renameFile calls.  The new one interleaves
> putDirs & renameFile calls.  In general, ">>" is not commutative, though in
> this case you may be as happy with either order.  - Conal

Right.  That's really why I wanted to change it.  It should do both
actions for each element in one pass over the list.


> On 12/12/06, Bryan Burgers <bryan.burgers at gmail.com> wrote:

> > Before we get too far down the obfuscation road, I'd like to offer
> > what I think is more readable than a liftM2 solution:
> >
> >    mapM_ (\p -> putDirs p >> uncurry renameFile p) pairs
> >
> > I haven't tested it, but I hope that does the same thing. To me, this
> > explicitely shows what each is doing, moreso than with a point-free
> > 'foo' combinator.
> >
> > The way my mind worked to get to this solution:
> >
> >    mapM_ putDirs pairs
> >    mapM_ (uncurry renameFile) pairs
> >
> > ==>
> >
> >    mapM_ (\p -> putDirs p) pairs
> >    mapM_ (\p -> uncurry renameFile p) pairs
> >
> > ==>
> >
> >    mapM_ (\p -> putDirs p >> uncurry renameFile p) pairs
> >
> > Is that a reasonable solution?

That works too. I don't know if I consider the liftM2 solution
obfuscated yet, but you're right, it could be leaning that way.
Thanks for the alternative suggestion.


-- 
Lou.


More information about the Haskell-Cafe mailing list