In a series of old posts, I once talked about the link between lists and monoids, as well as monoids and monads. Now I want to talk a little bit more about monoids and monads from the perspective of free structures.
List is a free monoid. That is, for any given type A, List[A] is a monoid, with list concatenation as the operation and the empty list as the identity element.
1
2
3
4
def freeMonoid[A]: Monoid[List[A]] = new Monoid[List[A]] {
def unit = Nil
def op(a1: List[A], a2: List[A]) = a1 ++ a2
}
B...
Published on February 15, 2015 01:58