In reading Wadler's original paper Monads for Functional Programming (1992), I feel as if I'm getting it, but, in the non-monadic description of a state handler, he shows the proto-monadic description of a State:
type M a = State -> (a, State)
eval :: Term -> M Int
eval (Con a) x = (a, x)
And it stopped making sense again. How am I supposed to read this? As I understand it, this says that eval takes an int and a state and returns a function that takes a state and returns a new pair (Int, State)
But... how does (a, x), which, if I'm reading this right is a tuple of a value and a state, is-a "function that takes a state and returns a new pair (Int, State)"?
Expand the type synonym: Term -> M Int
is equivalent to Term -> State -> (Int, State)
.
Alternately, think of the function definition as eval (Con a) = \x -> (a, x)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With