If you're familiar with functional language styles and you want an advanced look at how your favorite functional styles are supported in modern C++, with a dash of Haskell, check out these three videos by Bartosz Milewski:
Functional Patterns in C++ (slides)
by Bartosz Milewski
Part 1, Functors: First the introduction to some common functional patterns like Functor, which, surprisingly pops up everywhere. I'll show the example of a
unique_ptr
and avector
as Functors. Of course, this is only in preparation for asynchronous functors.Part 2, Currying, Applicative: A little digression to Haskell and the Maybe functor and the explanation of currying. Then I'll show you the Applicative Functor pattern. This is, of course, in preparation for for the asynchronous applicative functor pattern.
Part 3, Asynchronous API, Monoid, Monad: The encapsulation of asynchronous API that doesn't lead to inversion of control and spaghetti code. Very natural example of a Monad Pattern.
Interestingly, Bartosz' talk ends with a plea for (essentially) future.then
and a C#-style await
... both of which are under active consideration in the C++ standards committee as part of a potential near-term C++ technical specification on concurrency and parallelism.
Add a Comment
Comments are closed.