September 2017
Beginner to intermediate
396 pages
9h 46m
English
The Monoid class is defined as follows:
class Monoid a where mempty :: a mappend :: a -> a -> a mconcat :: [a] -> a
The mempty function defines a default value. The mappend function defines that as a result of combining two values of a, we will get a single value of type a. mconcat indicates that we can combine all the values in the list to produce a single value of type a. To define a Monoid instance, we need to define at least mempty and mappend functions:
Laws of Monoid--The monoid instance should follow this law:
mappend x mempty = x (Appending the default value should not change the value)
mappend mempty x = x (Appending a value to the default value is the same as value)
mappend x (mappend y z) = mappend (mappend ...
Read now
Unlock full access