[Haskell-beginners] Sum a tuple of Monoids

David McBride toad3k at gmail.com
Tue Nov 1 15:58:07 UTC 2016


I don't know if there is generally, but some people would use the lens
library to do such things.

import Control.Lens
> sumOf (each . _Just) (Just 1, Nothing, Just 2)
3

Just keep in mind that each member of the tuple must be the same type.

On Tue, Nov 1, 2016 at 11:42 AM, Lai Boon Hui <laiboonh at gmail.com> wrote:

> Hi all,
>
> Is it possible to sum a tuple of monoids for example
>
> sum (Just 1, Nothing)
>
> expected result Just 1
>
> sum (Just 1, Just 2)
>
> expected result Just 3
>
> --
> Best Regards,
> Boon Hui
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20161101/559849aa/attachment.html>


More information about the Beginners mailing list