Post · 2 min read· pp. 16–17

The constructive lift monad

The constructive lift monad is the coinductive type T(A)≡να.  A+α.T(A) \equiv \nu\alpha.\; A + \alpha.

The intuition is that an element of this type either tells you a value of type AA, or tells you to compute some more and try again. Nontermination is modeled by the element which never returns a value, and always keeps telling you to compute some more.

Our goal is to construct a general fixed-point combinator μ(f:TA→TA):1→TA\mu(f : TA \to TA) : 1 \to TA, which takes an ff and then produces a computation corresponding to the fixed point of ff. To fix notation, we'll take the constructors to be:

roll:A+TA→TAunroll:TA→A+TA\begin{array}{lcl}\mathsf{roll} & : & A + TA \to TA \\\mathsf{unroll} & : & TA \to A + TA \end{array}
Since this is a coinductive type, we also have an unfold satisfying the following equation:
unfold(f:X→A+X):X→TA≡roll∘(id+(unfold  f))∘f\mathsf{unfold}(f : X \to A + X) : X \to TA \equiv \mathsf{roll} \circ (\mathit{id} + (\mathsf{unfold}\; f)) \circ f
First, we will explicitly construct the bottom element, corresponding to the computation that runs forever, with the following definition:
⊥:1→TA≡unfold(inr)\bot : 1 \to TA \equiv \mathsf{unfold}(\mathsf{inr})
This definition just keeps telling us to wait, over and over again. Now, we can define the fixed point operator:
μ(f:TA→TA):1→TAμ(f)≡(unfold(unroll∘f))∘⊥\begin{array}{l}\mu(f : TA \to TA) : 1 \to TA \\\mu(f) \equiv (\mathsf{unfold} (\mathsf{unroll} \circ f)) \circ \bot\end{array}
What this does is to pass bottom to ff. If ff returns a value, then we're done. Otherwise, ff returns us another thunk, which we can pass back to ff again, and repeat.

Of course, this is exactly the intuition behind fixed points in domain theory. Lifting in domains is usually defined directly, and I don't know who invented the idea of defining it as a coinductive type. I do recall a 1999 paper by Martin Escardo which uses (a slight variant of) it, and he refers to it as a well-known construction in metric spaces, so probably the papers from the Dutch school of semantics are a good place to start the search. This construction has seen a renewed burst of interest in the last few years, since it offers a relatively convenient way to represent nonterminating functions in dependent type theory. It's also closely related to step-indexed models in operational semantics, since, given a terminating element of the lift monad, you can compute how many steps it takes to return a value.

It's stuff like this that makes me say I can't tell the difference between operational and denotational semantics any more.