In code:
smash :: Monoid a => a -> a -> a
empty :: Monoid a => a
A monoid is a property of things, not languages, so the idea of "a language without a monoid" doesn't really make sense.In code:
smash :: Monoid a => a -> a -> a
empty :: Monoid a => a
A monoid is a property of things, not languages, so the idea of "a language without a monoid" doesn't really make sense.Function of arity-2 (possibly expressed as an infix operator)
Which is closed over the set of values that are its arguments/parameters
For a domain (set of input values) which contains a value that converts the function into an identity function when used.
E.g. -
Addition over real numbers (or integers...), becomes an identity function when one arg is 0
Multiplication over real numbers (or integers...), becomes an identity function when one arg is 1
Something along that line?
I guess that makes it useful for a fold/reduce type function where the final result is the same type as the input stream, and the initial value can be identified as a known default.
Lists under concatenation Booleans under AND Booleans under OR Numbers under max Numbers under min
instance Monoid Int where
smash 25 x = x
smash x 25 = x
smash x y = 2*x^2 - 3*x*y
empty = 25
Thanks for explaining! 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.)---
> 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.