[Haskell-cafe] I think I discovered my first Monoid instance
Andrew Butterfield
Andrew.Butterfield at scss.tcd.ie
Tue Sep 29 09:41:08 UTC 2020
Hmmm - I thought so at first
A B A `xor` B
0 0 0
0 1 1
1 0 1
1 1 0
0 `xor` b = b
a `xor` 0 = a
Looks like 0 is the identity to me.
Regards, Andrew
> On 29 Sep 2020, at 10:33, Ben Franksen <ben.franksen at online.de> wrote:
>
> Am 29.09.20 um 10:27 schrieb Mario Lang:
>> instance Monoid QuadBitboard where
>> mempty = QBB 0 0 0 0
>>
>> -- | bitwise XOR
>> instance Semigroup QuadBitboard where
>> QBB b0 b1 b2 b3 <> QBB b0' b1' b2' b3' =
>> QBB (b0 `xor` b0') (b1 `xor` b1') (b2 `xor` b2') (b3 `xor` b3')
>>
>> But maybe I am violating some laws
>
> The Semigroup is okay, since 'xor' is indeed associative, and your
> instance basically lifts it to 4-tuples.
>
> The Monoid instance is wrong, though. There is no unit for 'xor'!
>
> Cheers
> Ben
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
--------------------------------------------------------------------
Andrew Butterfield Tel: +353-1-896-2517 Fax: +353-1-677-2204
Lero at TCD, Head of Software Foundations & Verification Research Group
School of Computer Science and Statistics,
Room G.39, O'Reilly Institute, Trinity College, University of Dublin
http://www.scss.tcd.ie/Andrew.Butterfield/
--------------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20200929/dfb69cc1/attachment.html>
More information about the Haskell-Cafe
mailing list