November 2017
Intermediate to advanced
670 pages
17h 35m
English
Monads are implemented as a type class with two methods, return and bind (>>=):
class Monad m where return :: a -> m a (>>=) :: m a -> (a -> m b) -> m b
Note that m refers to a type constructor, such as Either or Maybe, that implements the Monad type class.
We'll include a few more monadic functions from the Standard Library in the following table:
|
Function |
Description |
|
fail |
The fail function supports a monad's implementation of failure. We get the fail function from the Monad type class, and it enables a failed pattern matching to result in a failure in the context of the current monad instead of a program crash. For example, the fail function is called when pattern matching fails in a do expression. fail :: ... |