[Haskell-cafe] Generalizing catMaybes
Brandon S Allbery KF8NH
allbery at ece.cmu.edu
Sat Jan 8 04:34:39 CET 2011
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 1/7/11 21:56 , Tony Morris wrote:
> I am wondering if it possible to generalise catMaybes:
>
> (Something f, SomethingElse t) => t (f a) -> t a
>
> I have being doing some gymnastics with Traversable and Foldable and a
> couple of other things from category-extras to no avail. Perhaps
> someone else's brain is molded into an appropriate shape to reveal an
> answer!
Looks to me like you want something like:
> mtraverse :: (Traversable t, Monoid m) => t m -> m
> mtraverse xs = traverse mappend (mempty:xs)
or possibly the same kind of thing using MonadPlus instead of Monoid.
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe at haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
- --
brandon s. allbery [linux,solaris,freebsd,perl] allbery at kf8nh.com
system administrator [openafs,heimdal,too many hats] allbery at ece.cmu.edu
electrical and computer engineering, carnegie mellon university KF8NH
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAk0n20AACgkQIn7hlCsL25V0MACeIJjbHmIjnABHxpykeVdcZ62f
fS0AoL2xet/PpuvyuioWNvbzCTqWz5Z/
=2HGT
-----END PGP SIGNATURE-----
More information about the Haskell-Cafe
mailing list