[Haskell-beginners] Function for working with functions in data?
Brandon S Allbery KF8NH
allbery.b at gmail.com
Fri May 6 21:13:01 CEST 2011
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 5/6/11 14:57 , Mike Meyer wrote:
> I'm filling a functional itch that Haskell isn't scratching. I'm
> looking for a function to take a list of functions, and apply them all
> to a value. The signature is obvious :: [a -> b] -> a -> [b], and it's
> nearly trivial to write (\fs a -> map ($ a) [fs]), but Haskell has
> most useful list functions already provided.
It's there, but it's not a dedicated function; it's "sequence" applied to
the environment monad (-> e).
Prelude Control.Monad.Reader> :t sequence
sequence :: (Monad m) => [m a] -> m [a]
Prelude Control.Monad.Reader> :t sequence [(+1),(*2),(`subtract` 3)]
sequence [(+1),(*2),(`subtract` 3)] :: (Num a) => a -> [a]
- --
brandon s. allbery [linux,solaris,freebsd,perl] allbery.b at gmail.com
system administrator [openafs,heimdal,too many hats] kf8nh
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAk3ESD0ACgkQIn7hlCsL25XFeQCgnD2GTT4sjYKJ5Nw9QGG+qGJb
8NkAoKq07s8sUxjqw3CthG/0HNiKwnlU
=ifKQ
-----END PGP SIGNATURE-----
More information about the Beginners
mailing list