Using Monads in C++ to Solve Constraints: 1. The List Monad -- Bartosz Milewski

Bartosz Milewski starts to explain Monads in his recent article.

Using Monads in C++ to Solve Constraints: 1. The List Monad

by Bartosz Milewski

From the article:

I am sometimes asked by C++ programmers to give an example of a problem that can’t be solved without monads. This is the wrong kind of question — it’s like asking if there is a problem that can’t be solved without for loops. Obviously, if your language supports a goto, you can live without for loops. What monads (and for loops) can do for you is to help you structure your code. The use of loops and if statements lets you convert spaghetti code into structured code. Similarly, the use of monads lets you convert imperative code into declarative code. These are the kind of transformations that make code easier to write, understand, maintain, and generalize.

So here’s a problem that you may get as an interview question. It’s a small problem, so the advantages of various approaches might not be immediately obvious, especially if you’ve been trained all your life in imperative programming, and you are seeing monads for the first time.

Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.