Copyright | (c) 2015 Chris Hodapp |
---|---|
Safe Haskell | None |
Language | Haskell2010 |
- type IonCont a b = Def (b :-> ()) -> Ion (Def (a :-> ()))
- lift :: (IvoryType a, IvoryVar a, IvoryType b, IvoryVar b) => (a -> b) -> IonCont `[a]` `[b]`
- accum :: (IvoryType a, IvoryVar a, IvoryStore a, IvoryZeroVal a, IvoryType b, IvoryVar b) => IonCont `[]` `[b]` -> IonCont `[a]` (a : `[b]`)
- join :: (a -> b -> c) -> IonCont t `[a]` -> IonCont t `[b]` -> IonCont t `[c]`
Documentation
= Def (b :-> ()) | Continuation function |
-> Ion (Def (a :-> ())) | Entry function |
This wraps a pattern of functions calling each other in
continuation-passing style. The intent is that the returned entry
function (which takes arguments a
) causes the supplied
continuation function to be called (passing arguments b
).
This is a common pattern for asynchronous calls, for instance, in which the callback or interrupt calls the continuation function.
Multiple calls of this sort can be composed with '(=<<)' (and with
RecursiveDo
and mdo
) to chain them in the order in which they
would proceed.
For instance, in start <- call1 =<< call2 =<< call3 final
,
start
contains the entry function to call1
, whose continuation
is set to the entry function of call2
, whose continuation in turn
is set to the entry function of call3
, whose continuation is
final
. Note that chaining these with '(>>=)' is possible too,
but the order is somewhat reversed from what is logical - hence,
mdo
often being sensible here.
lift :: (IvoryType a, IvoryVar a, IvoryType b, IvoryVar b) => (a -> b) -> IonCont `[a]` `[b]` Source
Lift
a Haskell function up into an IonCont
.
accum :: (IvoryType a, IvoryVar a, IvoryStore a, IvoryZeroVal a, IvoryType b, IvoryVar b) => IonCont `[]` `[b]` -> IonCont `[a]` (a : `[b]`) Source
Accumulate
an argument into a continuation function.
Specifically: Given an IonCont
taking some argument in its entry
function, generate another IonCont
with the same type of entry
function, but whose continuation function contains another argument
(which will receive the same value of that argument).
Note that every use of this requires a static variable of type a
.
Also, this implementation does not protect against the continuation
function being called without the entry function; if this occurs,
the continuation will contain old values of a
from earlier
invocations, or possibly a zero value.
TODO: Right now this handles only converting single-argument to
double-argument. I intend to modify this to work similarly to
call
and callAux
in Ivory.