Boosting MPL with Haskell elements

The similarities of Haskell and C++ template metaprogramming is known [1,2], but a number of Haskell language elements have not been introduced into C++ template metaprogramming.

Haskell, like many other functional languages uses let expressions to support the programmer in writing more readable code. Let expressions could simplify the complex syntax of template metaprograms.

Monads together with Haskell's do notation help reducing the amount of boilerplate code and making the code more compact. Having them in template metaprograms would also be useful.

List comprehension simplifies list transformations and makes the code more readable. It can be easily implemented using the do notation and list monads together. Therefore, this can be used in template metaprograms as well.

Error handling can be simplified using the either monad. By adding some syntactic sugar to it, exception handling can be simulated in C++ template metaprograms. Even though, the either monad is needed to implement exception handling, the resulting code is simple and developers can understand it without deep knowledge about Monads.

The extenstions to template metaprogramming are available as an open source library. The implementation is compatible with Boost.MPL and can be easily introduced into projects already using Boost.MPL. The library can be found here:

This is an advanced talk, the audience is assumed to be familiar with Boost.MPL.

[1] Stuart Golodetz – Functional programming using c++ templates (part 1)

[2] Bartosz Milewski – What does Haskell have to do with C++?

Speaker: Ábel Sinkovics


Go back