We're going to come at continuations from three different directions, and each
time we're going to end up at the same place: a particular monad, which we'll
We're going to come at continuations from three different directions, and each
time we're going to end up at the same place: a particular monad, which we'll
-------------------------
To construct a monad, the key element is to settle on how to implement its type, and
-------------------------
To construct a monad, the key element is to settle on how to implement its type, and
some previously unconnected elements of the course (more specifically,
version 3 lists and monads).
some previously unconnected elements of the course (more specifically,
version 3 lists and monads).
an `'a reader` is `env -> 'a` (by definition), the type of the
`r_unit` function is `'a -> env -> 'a`, which is an instance of the
type of the **K** combinator. So it makes sense that **K** is the unit
an `'a reader` is `env -> 'a` (by definition), the type of the
`r_unit` function is `'a -> env -> 'a`, which is an instance of the
type of the **K** combinator. So it makes sense that **K** is the unit
let s_bind (u : 'a state) (f : 'a -> 'b state) : 'b state =
fun (s : store) -> let (a, s') = u s in f a s'
let s_bind (u : 'a state) (f : 'a -> 'b state) : 'b state =
fun (s : store) -> let (a, s') = u s in f a s'
won't pause to explore it here, though conceptually its unit and bind
follow just as naturally from its type constructor.
won't pause to explore it here, though conceptually its unit and bind
follow just as naturally from its type constructor.
will provide a connection with continuations.
Recall that `List.map` takes a function and a list and returns the
will provide a connection with continuations.
Recall that `List.map` takes a function and a list and returns the
type `('something list) list`. We can eliminate that restriction by flattening
the list of lists into a single list: this is
just `List.concat` applied to the output of `List.map`. So there is some logic to the
type `('something list) list`. We can eliminate that restriction by flattening
the list of lists into a single list: this is
just `List.concat` applied to the output of `List.map`. So there is some logic to the
Yet we can still desire to go deeper, and see if the appropriate bind
behavior emerges from the types, as it did for the previously
Yet we can still desire to go deeper, and see if the appropriate bind
behavior emerges from the types, as it did for the previously
(* an intermediate version, and the fully eta-reduced: *)
fun k -> u (fun a -> f a k)
(* an intermediate version, and the fully eta-reduced: *)
fun k -> u (fun a -> f a k)
-Consider the most eta-reduced versions of `l'_unit` and `l'_bind`. They're the same as the unit and bind for the Montague continuation monad! In other words, the behavior of our v3-list monad and the behavior of the continuations monad are
+Consider the most eta-reduced versions of `l'_unit` and `l'_bind`. They're the same as the unit and bind for the Montague Continuation monad! In other words, the behavior of our v3-List monad and the behavior of the continuations monad are
parallel in a deep sense.
Have we really discovered that lists are secretly continuations? Or
have we merely found a way of simulating lists using list
continuations? Well, strictly speaking, what we have done is shown
that one particular implementation of lists---the right fold
parallel in a deep sense.
Have we really discovered that lists are secretly continuations? Or
have we merely found a way of simulating lists using list
continuations? Well, strictly speaking, what we have done is shown
that one particular implementation of lists---the right fold
and that this monad can reproduce the behavior of the standard list
monad. But what about other list implementations? Do they give rise
to monads that can be understood in terms of continuations?
and that this monad can reproduce the behavior of the standard list
monad. But what about other list implementations? Do they give rise
to monads that can be understood in terms of continuations?