4 ms·
There are also the monoid "laws" (not checked in Haskell): empty `smash` x = x -- left identity x `smash` empty = x -- right identity (x `smash` y)
by mjhoy 9y ago
There are also the monoid "laws" (not checked in Haskell):
empty `smash` x = x -- left identity
x `smash` empty = x -- right identity
(x `smash` y) `smash` z = x `smash` (y `smash` z) -- associativity
Your definition doesn't fit any of these. (Edit: you've rewritten to meet the first two; but it is not associative.)
- conistonwater 9y agoThey are not checked in Haskell, but they are definitely relied on by existing code.
- catnaroek 9y agomightybyte didn't state the associativity law in his original definition. As for the left and right identity laws, he did state them, and I did intend my instance to satisfy them (otherwise I wouldn't have special-cased 25, of course), but I messed up. I've fixed my post since.
- conistonwater 9y agoJust for reference, the laws are stated in full in haskell's docs, https://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Monoid.html https://hackage.haskell.org/package/base-4.10.0.0/docs/Data-....
- catnaroek 9y agoI was deliberately “acting stupid” to criticize an insufficiently precise definition. --- > That is usually a terrible idea. Not at all. Think about the structure of a proof of negation. You make a “silly” assumption and “play along” until you reach a contradiction.
- conistonwater 9y agoThat is usually a terrible idea.
- conistonwater 9y agoProofs by contradiction do not require you to play dumb, you can just present them as they are.
- mightybyte 9y agoI left out associativity because I was focusing on the ELI5 part.