package miou
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=bf1954c6f66ac9d306b3b4f948b19f59d2c327213af930e19d9fbc73f134fa18
sha512=cea8136bf9fef32898c962b4136fd784a20fc8a6626cd19bb7d0a37e798aa7a7f06ea9f19b47f6e03bb1afd477cf46e57d4c6a376601eb282c4fb07d490ca727
doc/miou/Miou_state/index.html
Module Miou_stateSource
The type of continuations. ('a, 'b) continuation is the state of a function _ -> 'b. 'a is the type of the value to continue the continuation. The user can also discontinue with an exception the continuation.
The type of errors. A continuation can raise or be cancelled by an exception. We keep the backtrace (where the exception comes from) with the exception raised/used.
type 'a t = private | Finished of ('a, error) result| Suspended : ('a, 'b) continuation * 'a Effect.t -> 'b t| Unhandled : ('a, 'b) continuation * 'a -> 'b t
The type of function states.
The state of a function is its execution state. A function can finish with its return value or an exception, or it can suspend on an Effect.t. In the case of a suspension, the user can "continue" the execution via what is expected by the associated effect. Note that once can only be used once on a given value t (otherwise, an exception Effect.Continuation_already_resumed is raised by OCaml).
Type of the effect handler.
perform is a function which should handle incoming effects and give an operation Operation.t via the given continuation k.
Predicate describing free effects: pure queries on the scheduler's state, which cost no quanta and on which a task must never be suspended.
make fn value makes a new function state by executing the function with the given argument.
suspended_with k eff allows you to create a state from the given suspension k and the effect eff which produced the given suspension. This function does not continue the given k, it is safe to use it even if the user resumed k elsewhere.
once ~perform state applies perform once on the given state if the latter emits an effect.
fail ~exn state discontinues the given state with the given exception. It always return Finished (Error exn). If the given state was already resumed elsewhere, this function traps the exception Effect.Continuation_already_resumed and return Finished (Error exn).
run ~quanta ~perform state applies once quanta times. If perform responds with Operation.interrupt (and therefore does nothing), even though there may be a few quanta left, the function returns the last state obtained.
The same applies to Operation.yield, except that the continuation has burnt itself out. In other words, Operation.yield is equivalent to send (); interrupt but costs only one quanta.