Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Sum a tuple of Monoids (Lai Boon Hui)
2. Re: Sum a tuple of Monoids (Imants Cekusins)
3. Re: Sum a tuple of Monoids (David McBride)
----------------------------------------------------------------------
Message: 1
Date: Tue, 1 Nov 2016 23:42:06 +0800
From: Lai Boon Hui <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Sum a tuple of Monoids
Message-ID:
<CAJdQggmVvzhP+wNSN6RaZRs5NQS2pnhbh5RkXQdQOK=ae8d...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20161101/674cacf4/attachment-0001.html>
------------------------------
Message: 2
Date: Tue, 1 Nov 2016 16:55:38 +0100
From: Imants Cekusins <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Sum a tuple of Monoids
Message-ID:
<CAP1qinYNVj=01BTSayKZxKAqQr=1_crbvu0vrldtatzn1j_...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
> sum a tuple of monoids
here is something, not quite what you are looking for, but close:
Monoid
<http://hackage.haskell.org/package/base-4.9.0.0/docs/Data-Monoid.html#t:Monoid>
a
=> Monoid
<http://hackage.haskell.org/package/base-4.9.0.0/docs/Data-Monoid.html#t:Monoid>
(Maybe
<http://hackage.haskell.org/package/base-4.9.0.0/docs/Data-Maybe.html#t:Maybe>
a)
(Monoid
<http://hackage.haskell.org/package/base-4.9.0.0/docs/Data-Monoid.html#t:Monoid>
a, Monoid
<http://hackage.haskell.org/package/base-4.9.0.0/docs/Data-Monoid.html#t:Monoid>
b)
=> Monoid
<http://hackage.haskell.org/package/base-4.9.0.0/docs/Data-Monoid.html#t:Monoid>
(a,
b)
mappend (Just [1], Just [2,3]) (Nothing, Just [5])::(Maybe [Int],Maybe
[Int])
(Just [1],Just [2,3,5])
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20161101/f4ce93e5/attachment-0001.html>
------------------------------
Message: 3
Date: Tue, 1 Nov 2016 11:58:07 -0400
From: David McBride <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Sum a tuple of Monoids
Message-ID:
<CAN+Tr41QHe377c2z+92fjy7GmYpFt-VC47JFRf=7vtsizk2...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
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 <[email protected]> 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
> [email protected]
> 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-0001.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 101, Issue 2
*****************************************