Monads are a common technique in functional programming languages to reduce boilerplate, abstract detail in order to produce simple, pure pipelines. While traditionally associated with languages like Haskell, monads are making their way into more mainstream languages, including C -- with monadic operations being added in C23. In time, these functional techniques may become core pillars of C++ development.
To many developers, monads are either unknown or confusing — they have a reputation as being notoriously difficult to understand. This talk, which will combine both theory and coding examples, aims to demystify the monad and enable attendees to gain insight into its internal workings.
While the focus of our talk will be on C, the ideas are relevant to any other programming language -- the shift towards these functional features is not unique to C.
No functional programming knowledge required.
This talk will serve as an introduction to the monad design pattern. We will start by introducing functors (a related pattern) and use it as a building block to introduce monads. Throughout the presentation, we will show examples of how monadic operations can help turn our imperative-style code into succinct functional pipelines, while removing boilerplate, error-prone control flow, and side effects. The examples will relate to recent and upcoming developments for std::vector and std::optional in the C standard. Finally, the talk will incorporate a walk-through of the available monadic support in C, and we will discuss where C++ stands in comparison to other languages.