Monad Transformers
Monad Transformers is an important pattern of purely functional programming that allows us to combine effect types. Let's now discuss it in detail.
The specialization of effect types
We've discussed how effect types are ubiquitous in purely functional programming and are used in order to abstract away side effects. You may have also noticed that these types are highly specialized, which means we have almost one-to-one mapping between side effects and effect types. For example, the ability of an application to return null is represented by an Option
side effect type. Option
is good for such null situations. However, it does not perform well when tasked with modeling errors and exceptions. This is because it does not preserve the information of the nature of the failure.
A data type that is good for modeling erroneous computation that can fail is Either
. However, if you try to model a computation that returns null with Either
, you will find that this data type is redundant...