[Haskell-cafe] I think I discovered my first Monoid instance

Oleg Grenrus oleg.grenrus at iki.fi
Tue Sep 29 09:51:23 UTC 2020


xor a b = (a + b) mod 2

Many good properties follow. https://en.wikipedia.org/wiki/GF(2) ...

- Oleg

On 29.9.2020 12.45, Andrew Butterfield wrote:
> Not only that, `xor` has inverses so it forms an abelian group
>
> Regards, Andrew
>
>> On 29 Sep 2020, at 10:41, Andrew Butterfield
>> <Andrew.Butterfield at scss.tcd.ie
>> <mailto:Andrew.Butterfield at scss.tcd.ie>> wrote:
>>
>> 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
>>> <mailto: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/
>> --------------------------------------------------------------------
>>
>> _______________________________________________
>> 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/
> --------------------------------------------------------------------
>
>
> _______________________________________________
> 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20200929/f794a138/attachment.html>


More information about the Haskell-Cafe mailing list