Monads are everywhere… Maybe that’s bad? by Till Schröder

October 12, 2022

Till Schröder discusses the use of monads as a pattern for handling effects and chaining functions, with examples from various programming languages like JavaScript, Haskell, and C#. Monads, which can be thought of as a way to overload the semicolon, provide a more flexible way to handle errors and chain functions with effects. However, monads have challenges, such as the requirement for having the same error type for monadic computations and the complexity of implementing them in some languages.

Till also introduces the concept of algebraic effects as an alternative to monads, which can handle side effects and exceptions in a more user-friendly way but are more complex to implement. Despite the challenges, Till expresses his fascination with the history of programming languages and his enjoyment of experimenting with various languages.

Till Schröder starts by introducing the historical context, tracing back to McCarthy’s Lisp and the idea of “eval” as an early form of algebraic effects. Till then delve into the origins of exceptions and how exceptions evolved into monads, showcasing an implementation in Haskell. The presentation emphasizes that monads are commonly misunderstood and associated with functional programming languages like Haskell.

The presentation proceeds with an explanation of monads’ practical applications, highlighting their role in error handling, async programming, and list comprehensions in languages like JavaScript, C#, and F#. The speaker mentions that monads gained traction because they are easy to implement, and showcase how monads influenced languages like JavaScript through async/await.

Next, the talk shifts to algebraic effects as an alternative to monads. Algebraic effects allow for a more flexible way of handling effects and have the potential to address some downsides of monads, like composability and specific error handling. However, implementing algebraic effects in existing languages is challenging, and there are currently no production-ready languages supporting them fully. The speaker encourages further exploration of algebraic effects due to their potential for future language design.

Throughout the presentation, Till engages in a conversation with the audience, answering questions and providing additional insights. Overall, the talk provides a broad overview of monads, algebraic effects, and their historical context, encouraging further exploration and research in the field.

 

Additional resources

Check out more from the MeetUp Func Prog Sweden. Func Prog Sweden is the community for anyone interested in functional programming. At the MeetUps the community explore different functional languages like Erlang, Elixir, Haskell, Scala, Clojure, OCaml, F# and more.