haskellmonadsfunctormonoidsarrow-abstraction

Using monads, monoids, functors and arrows in practice


I recently ran into this post about useful resources for different aspects of functional programming, such as monads and monoids, etc.

But the question is - what use can an average programmer make out of such concepts. I often run into "academic" researches about those issues. However, I've never met in practice (in a real project) anyone using them.

So the question is - are there any widely-used open-source projects in Haskell that really make use of such things, such projects that demonstrate the actual necessity of this concepts in "production" software, not in the "academic" software written "just for fun". It would be cool to make a list like this:


Solution

  • Many of these concepts are so implicit in Haskell code it's easier to list examples that don't use them (assuming you can find one). Every Haskell program uses monads, at least for IO.

    All of these are widely used because they're abstractions that appear very frequently in code. Consider functors: mapping over a containers is a fairly common need, so it makes sense to have a single interface for any container-like data structure, which is exactly what Functor provides. It happens that even the concept of a "container" is more concrete than the functor abstraction, but hopefully this demonstrates the point.

    Monads: The XMonad window manager is a widely-used program which makes extensive use of monad transformers and the zipper structure. STM is a library that provides a new monad with useful properties.

    Monoids: the Sequence structure in the containers package is implemented with monoids. Also, monoids are widely used to model sets, lists, and similar because the two monoid operations provide an empty list and concatenation (or an empty set and union).

    Arrows: Yampa and HXT (Haskell XML Toolbox) immediately come to mind.

    Functors show up everywhere. It's fairly common for monadic code to have a lot of <$>s, which means that the Functor instance is in use. Most Haskell parsers make heavy use of functors.