News for hackers. Stuff that matters.
Re:Algebraic patterns – Semigroup by alipang on Friday July 22, 2016 @07:37AM (#12142950)
Comparators are not composed by ordinary function composition, but by pointwise composition in the domain. If you can read Haskell

    instance Monoid a => Monoid (b -> a) where
       f <> g = \x -> f x <> g x
Here they type a is the set `{ EQ, LESS, GREATER }` which is in turn composed in a left-biased way with `EQ` as an identity.

If you have two comparators, `lastNameComparator` and `firstNameComparator` and compose them into a comparator that compares first by firstName, then by lastName, surely that is a closed operation. It is also associative, and comparators do have an identity, so, yes they are also monoids.

There are no comments on this comment yet.