- Given
a: Option α
andf : α → β
we get a term of typeOption β
by writinga.map f
. - Given
a: Option α
andf: α → Option β
we get a term of typeOption β
by writinga.bind f
.
For both these it is more pleasant to use the do
notation.
Equivalent to the second is that there is a function Option Option α → Option α
called join
.
IO Monad #
Roughly wraps with the state of the real world.
For example, a random number is wrapped in this.
Question:: Why not just ℕ
?
- Otherwise we will violate the principle that the value of a function is determined by its arguments.
We still do want a natural number. To get this we can run
the IO
computation.
This does not lead to a contradiction, though in a way that may be somewhat surprising.