N. Sculthorpe, J. Bracker, G. Giorgidze, and A. Gill, “The constrained-monad problem,” in Proceedings of the 18th ACM SIGPLAN International Conference on Functional Programming, pp. 287–298, ACM, 2013.



In Haskell, there are many data types that would form monads were it not for the presence of type-class constraints on the operations on that data type. This is a frustrating problem in practice, because there is a considerable amount of support and infrastructure for monads that these data types cannot use. Using several examples, we show that a monadic computation can be restructured into a normal form such that the standard monad class can be used. The technique is not specific to monads, and we show how it can also be applied to other structures, such as applicative functors. One significant use case for this technique is domain-specific languages, where it is often desirable to compile a deep embedding of a computation to some other language, which requires restricting the types that can appear in that computation.


  author = {Neil Sculthorpe and Jan Bracker and George Giorgidze and Andy Gill},
  title = {The Constrained-Monad Problem},
  booktitle = {Proceedings of the 18th ACM SIGPLAN International Conference on Functional Programming},
  publisher = {ACM},
  location = {Boston, Massachusetts},
  pages = {287--298},
  year = {2013},