[Haskell-cafe] Mapping a list of functions
Gregory Collins
greg at gregorycollins.net
Thu Jun 17 15:19:55 EDT 2010
Martin Drautzburg <Martin.Drautzburg at web.de> writes:
> Hello all
>
> The standard map function applies a single function to a list of arguments.
> But what if I want to apply a list of functions to a single argument. I can
> of course write such a function, but I wonder if there is a standard way of
> doing this,
> (map ($ 3) [(+2), (*4), (/3)])::[Double]
[5.0,12.0,1.0]
> Related to that is the problem, that the function in map may require more than
> one argument, so I need to apply it partially to some value(s) first. But
> what if I want to fix its second and third argument and not its first
> argument? Can flip help?
The "pointfree" command-line tool can help you find good short forms for
this kind of thing:
$ pointfree '\x -> f x 2 3'
flip (flip f 2) 3
In this case the explicit (pointed) lambda is simpler so I would usually
just use that.
G
--
Gregory Collins <greg at gregorycollins.net>
More information about the Haskell-Cafe
mailing list