[Haskell-cafe] Mapping a list of functions

Alexander Solla ajs at 2piix.com
Thu Jun 17 15:11:24 EDT 2010


On Jun 17, 2010, at 12:02 PM, Martin Drautzburg wrote:

> 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,

Use Control.Applicative, and the <*> operator.  Something like [f, g,  
h, i, j] <*> pure x (which equals [f x, g x, h x, i x , j x])

> 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?

I think the <$> operator can help here.  Also, don't forget plain old  
lambda abstraction to abstract over a free variable.


More information about the Haskell-Cafe mailing list