" Recently I looked at some code I wrote 8 months ago and was shocked! I looked at one file written in “good OO-style”, lots of inheritance and code reuse, and just thought “this is just a monoid and a bunch of crap because I didn't realise this is a monoid” so I rewrote the entire thing to about a third of the code size and ended up with double the flexibility. Shortly after I saw another file and this time thought “these are all just endofunctors,” and lo and behold, rewrote it to about a third of the code size and the final product being both easier to use and more powerful."

That would be so much more useful if it came with the examples.

1. What does this code do?\n2. Where is this previous code this replaced that was 3 times the size?

I've seen a lot of code that was larger than necessary because the author didn't know what a Monoid or Functor were.

Cf. "Visitor pattern"

I wasn't ignorant enough at the time I wrote the code to fuck up in the way you describe. I can only show an example of stuff I've made.

Here we go, three more uses of Monoidic functions (mempty, mappend)

https://github.com/bitemyapp/bloodhound/blob/master/Database...

It's not just about code, it's about conceptual memoization.

If you know what a Monoid is and you're learning how a data type like ByteString works, you can intuit how to "stitch" bytestrings together as well as how to get an "empty" ByteString.

It's about killing off unnecessarily ad-hoc APIs as much as anything.

Being able to realize when you're implementing a Functor/Monoid/Applicative/Monad is powerful because it lends you intuition on what the rules for a well-behaved API are and allow powerful, polymorphic code-reuse.

Consider the reusability of the functions here across the vast set of Monadic types out there: http://hackage.haskell.org/package/base-4.7.0.0/docs/Control...

This is worth pondering as well: https://github.com/jwiegley/simple-conduit

The code savings described are usually associated with not having to rewrite the polymorphic generic functions used in the Haskell ecosystem for the one-off a person made. The conceptual power from having a community that understands these patterns is more important.

You'll learn more and faster by learning Haskell.

https://github.com/bitemyapp/learnhaskell