Solution

ID: past-exam-of-the-computer-science-course-of-the-university-of-oxford/2015/principles-of-programming-languages/2/a/solution

The continuation receives both the computed value and the current computer memory. Therefore return invokes it with unchanged computer memory, while sequencing installs a continuation that passes the produced value and updated computer memory to the next computation:
result :: a -> M a
result x k s = k x s

bind :: M a -> (a -> M b) -> M b
bind p f k s = p (\x s' -> f x k s') s
For left identity, expand the two definitions:
For right identity,
For associativity, both groupings reduce to the same expression:
By function extensionality, these establish all three monad laws:

New to topics? Read the docs here!