[Haskell-cafe] Name that function =)
conal at conal.net
Tue Dec 12 12:29:57 EST 2006
Try foo = liftM2, and check out the recent haskell thread "Cannot understand
Cheers, - Conal
On 12/12/06, Louis J Scoras <louis.j.scoras at gmail.com> wrote:
> Hi all;
> I'm new to the list, so I just wanted to say hi and -- of course --
> ask a quick question:
> I have some IO actions that I want to map over a list of pairs --
> these are just directory names and their down-cased versions. It
> wasn't difficult to actually get the right behavior by just doing mapM
> -- putDirs just outputs something like "mv fst snd"
> mapM_ putDirs pairs
> mapM_ (uncurry renameFile) pairs
> This bothered me though, because I suspected that this could be done
> in one pass. Naively I proceeded to this.
> mapM_ (putDirs >> (uncurry renameFile)) pairs
> Which didn't work. I thought about it a little more before realizing
> that putDirs wouldn't get any parameters this way: I needed some way
> to distribute the pair over both operations. Here's the higher-order
> function I needed:
> foo h f g i = h (f i) (g i)
> which could then be curried and we get:
> mapM_ (foo (>>) putDirs $ uncurry renameFile) pairs
> Works great. So my question: is there a established name for foo?
> What about foo partially applied to (>>)? This was a fun exercise,
> but I'd like to use the standard implementations if they exist.
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe