Maybe identities
In the monoid lesson, we posed this question: If each of the following four functions is the (<>)
operation for a semigroup, what is the identity value that makes it a monoid?
f3
Identity value: Just mempty
This one was slightly a trick question, because we have to strengthen the constraint on a
from Semigroup
to Monoid
in order to ensure that this identity value exists.
Note that Nothing
is not an identity for this function! Remember the identity laws. For all x
:
mempty <> x = x
x <> mempty = x
Take, for example, x = Just 1
. Then f3 Nothing (Just 1)
is Nothing
, not Just 1
, therefore we know that Nothing
is not an identity.
f4_first
Identity value: Nothing
f4_last
Identity value: Nothing
f4_both
Identity value: Nothing