In search of: [a->b] -> a -> [b]

Christian Sievers sievers@math2.nat.tu-bs.de
Thu, 19 Jun 2003 18:05:11 +0200


Derek Elkins wrote:

> >      flist :: [a->b] -> a -> [b]
> >      flist fs a = map (flip ($) a) fs
> or much nicer (IMO) 
>   flist fs a = map ($ a) fs 

This is a case where I'd prefer a list comprehension:

flist fs a = [ f a | f <- fs ]

(and this could be a monad comprehension, if Haskell still had them...)

> the generalized solution being simply,
> f mf x = do
>     f <- mf
>     return (f x)

Or just replace map by fmap in your flist from above.


All the best
Christian Sievers