computation

computation α is the type of unbounded computations returning α. An element of computation α is an infinite sequence of option α such that if f n = some a for some n then it is constantly some a after that.

computation.return

return a is the computation that immediately terminates with result a.

computation.think

think c is the computation that delays for one "tick" and then performs computation c.

computation.thinkN

thinkN c n is the computation that delays for n ticks and then performs computation c.

computation.head

head c is the first step of computation, either some a if c = return a or none if c = think c'.

computation.tail

tail c is the remainder of computation, either c if c = return a or c' if c = think c'.

computation.empty

empty α is the computation that never returns, an infinite sequence of thinks.

computation.run_for

run_for c n evaluates c for n steps and returns the result, or none if it did not terminate after n steps.

computation.destruct

destruct c is the destructor for computation α as a coinductive type. It returns inl a if c = return a and inr c' if c = think c'.

computation.run

run c is an unsound meta function that runs c to completion, possibly resulting in an infinite loop in the VM.

computation.corec

corec f b is the corecursor for computation α as a coinductive type. If f b = inl a then corec f b = return a, and if f b = inl b' then corec f b = think (corec f b').

computation.lmap

left map of

computation.rmap

right map of

computation.terminates

terminates s asserts that the computation s eventually terminates with some value.

computation.promises

promises s a, or s ~> a, asserts that although the computation s may not terminate, if it does, then the result is a.

computation.length

length s gets the number of steps of a terminating computation

computation.get

get s returns the result of a terminating computation

computation.results

results s a n completely characterizes a terminating computation: it asserts that s terminates after exactly n steps, with result a.

computation.map

Map a function on the result of a computation.

computation.bind

Compose two computations into a monadic bind operation.

computation.join

Flatten a computation of computations into a single computation.

computation.orelse

c₁ <|> c₂ calculates c₁ and c₂ simultaneously, returning the first one that gives a result.

computation.equiv

c₁ ~ c₂ asserts that c₁ and c₂ either both terminate with the same result, or both loop forever.

computation.lift_rel

lift_rel R ca cb is a generalization of equiv to relations other than equality. It asserts that if ca terminates with a, then cb terminates with some b such that R a b, and if cb terminates with b then ca terminates with some a such that R a b.