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:
A functor is an interface with one method i.e a mapping of the category to category. Monads basically is a mechanism for sequencing computations. A monad is a way to wrap stuff, then operate on the wrapped stuff without unwrapping it.
(->) is often called the "function arrow" or "function type constructor", and while it does have some special syntax, there's not that much special about it. It's essentially an infix type operator. Give it two types, and it gives you the type of functions between those types.
Functors are also important because they are a building block for applicatives and monads, which are coming in future posts.
In functional programming, a monad is a software design pattern with a structure that combines program fragments (functions) and wraps their return values in a type with additional computation.
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.
I'm using arrows and monads (and thus also functors) productively for real world applications. My functional reactive programming (FRP) library Netwire combines all four concepts you mentioned and more, and FRP itself is also a design pattern, which you usually know from academics. These are the concepts used:
Wire
type, which is an arrow transformer.Wire
usually transforms to a stack of monad transformers wrapped by a Kleisli
arrow.Version 3 is about to be released (I hope today), which will also bring (non-associated) type families into the game.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With