Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wadler's paper: How is a tuple a function?

Tags:

haskell

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)"?

like image 225
Elf Sternberg Avatar asked Sep 19 '14 22:09

Elf Sternberg


1 Answers

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).

like image 163
Christian Conkle Avatar answered Oct 16 '22 00:10

Christian Conkle