Just reading through category theory book , and decided to apply it to haskell.
The author defines Monoid as:
Monoid is a set L equipped with a binary operation *:LxL->L and a distinguished unit element u in L such that etc...
Taking a "List" structure as a monoid, it is clear that binary operation is concat
and unit is []
.
But what is the set M here? I tried L = {set of all lists}
but I think that leads me into trouble with "is L in L?" question, which seems to be the same problem as sets have.
Or am I thinking of something incorrectly?
EDIT: As pointed out by @applicative, Haskell's lists are monoids called the Free monoids !
Instead of saying "List is a Monoid", it would be more accurate to say "For all types a, the type [a]
is a Monoid". So for any particular type a
, your L will be L = {set of all lists of as}
. And with that definition, L can of course not contain itself.
For any type t
you can have that
L = all elements of the type [t]
then L is a monoid in the trivial way using ++
. In fact, we formalize this in Haskell
class Monoid m where
mempty :: m
mappend :: m -> m -> m
this is a "class" of types that have the requisite operations to form a monoid, so
instance Monoid [a] where
mempty = []
mappend a b = a ++ b
in fact, this is known as the "free monoid on a"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.