Clock is monoid

I bumped into "functional programming" several times during my years in college and now I'm planning to spend serious effort in learning it. My language of choice, after evaluating several, is Haskell.

But this post is not about Haskell. I mentioned Haskell because I encountered many mathmatical concepts when learning, such as functor, moinoid and monad. They are a bit far-fetched for me because I have a background of low level programming.

Recently I came across a video on Youtube, in which monoid is not depicted as pure mathmatical but something we know everyday. The clock we see everywhere is actually an instance of monoid.

For S with some binary operation 'dot' which maps S x S -> S to be a monoid, it has to sastify two axioms:

  • For all a, b and c in S, (a 'dot' b) 'dot' c = a 'dot' (b 'dot' c)
  • There exists identity element u that every elements a in set S a 'dot' u = u 'dot' a = a

For a clock, the identity element is 12 and 'dot' can be defined as 'dot' a b = (a + b) % 12.

Pretty neat, isn't it?

There's a lot of other information in that video. The discussion on composibility is quite delightful as well.

And here is the link.