Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You've definitely used Functors or Semigroups as well, you just didn't realize it.


Here is my problem with these ideas in programming: if you recognize that some common construct is in fact a semigroup or functor, does knowing this actually buy you anything?

I suppose it might help sometimes when designing an abstraction, to guide you to some nice properties, such as easy composition.


While playing around with a problem at work involving Markov chains and graph connectivity, I found it useful to know that I could write (in Java) a generic method that performed "exponentiation by squaring" on semigroups.

So, in addition to being able to raise numbers to powers I could also use it on matrices whose elements belonged to a semiring.

That is, I could use the same code on a matrix of doubles with "times" and "plus" (for the Markov chains), as well as a matrix of booleans with "and" and "or" (for the graph connectivity).

(Of course, I could have used special purpose libraries, but these were small problems and it was fun. :)


> if you recognize that some common construct is in fact a semigroup or functor, does knowing this actually buy you anything?

At least in Haskell one thing it means is you can use lots of new helper functions.

> guide you to some nice properties, such as easy composition.

Yep, which gets you code re-use for one.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: