On Thu, 19 Jun 2003 18:05:11 +0200 Christian Sievers <sievers@math2.nat.tu-bs.de> wrote:
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...)
I don't think Haskell ever had them (I'd have to check). Gofer did. Anyways, do-notation is about as expressive as monad comprehensions. With do-notation you have to add guards explicitly, but you don't have to end with a return and you don't need to bind variables, e.g. I believe [() | _ <- putStrLn "foo"] would be necessary (well, not in this case, but the general one).
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.
That generalizes it, but in a different way since (in Haskell) Monad isn't a subclass of Functor...