[Haskell-cafe] standard function

Dougal Stanton ithika at gmail.com
Wed Jun 6 10:14:14 EDT 2007


On 06/06/07, Steffen Mazanek <haskell at steffen-mazanek.de> wrote:
> Hello,
>
> is there a function f::[a->b]->a->[b] in the libraries? Couldn't find one
> using
> hoogle although this seems to be quite a common thing...
>

Possibly it's just too small to bother putting in a separate function.

> let fs = [ (*2), (+2), (2-) ]
> :t fs
> fs :: [Integer -> Integer]
> map ($5) fs
> [10,7,-3]
> :t map ($5)
> map ($5) :: (Num a) => [a -> b] -> [b]
> let g = \x -> map ($x)
> :t g
> g :: a -> [a -> b] -> [b]

That's essentially what you want, but we could go the extra distance.

> :t flip g
> flip g :: [a -> b] -> a -> [b]
> let h = flip g
> h fs (5)
> [10,7,-3]

> f fs i = map ($i) fs

D.


More information about the Haskell-Cafe mailing list