Type system
Factory type
Every occurrence of pecan.Co.co(...)
internally declares a new class that is a factory for instances of the created coroutine. This class cannot implement any particular interface, because every coroutine declaration may have a different number of arguments. Informally, the interface is:
interface CoFactory<T> { // T is the coroutine instance type
function run(args...):T;
function runSuspended(args...):T;
}
Instance type
Every occurrence of pecan.Co.co(...)
also declares an instance type. An instance represents a called coroutine and it is responsible for storing its internal state.
Every coroutine instance type implements the interface pecan.ICo<TIn, TOut, TRet>
, where:
TIn
is the input type (the type returned byaccept()
calls) orVoid
,TOut
is the output type (the argument provided toyield(...)
calls) orVoid
, andTRet
is the return type.
A Void
return type is always replaced by pecan.Void
, to avoid issues with Void cannot be used as a value
errors in Haxe.