Back to Fpinscala

16.Answer

answerkey/monads/16.answer.md

latest834 B
Original Source

Recall the identity laws:

left identity: unit(x).flatMap(f) == f(x) right identity: x.flatMap(unit) == x

The left identity law for Gen: The law states that if you take the values generated by unit(x) (which are always x) and apply f to those values, that's exactly the same as the generator returned by f(x).

The right identity law for Gen: The law states that if you apply unit to the values inside the generator x, that does not in any way differ from x itself.

The left identity law for List: The law says that wrapping a list in a singleton List and then flattening the result is the same as doing nothing.

The right identity law for List: The law says that if you take every value in a list, wrap each one in a singleton List, and then flatten the result, you get the list you started with.