Control.IOI
Church-encoded Free IOI Comonad is a comonadic state machine defined by an anamorphism. It represents a process that can interact with its environment.
Types
IOI :: * -> *
The Church-encoded Free IO Comonad. It represents a potentially infinite state-based process (a machine) defined by an anamorphism.
Implementationforall (x: *) . (forall (s: *) . s -> (s -> f r s) -> x) -> x
F :: * -> * -> *
The interaction functor for the IO stream. Describes the possible next steps of a process: output, input, or return.
Implementationforall (x: *) . (data -> s -> x) -> ((data -> s) -> x) -> (r -> x) -> x
Foreigns
get_line :: Data
Leaf FFI shared with IO. Reads input from console.
Implementationforeign get_line :: Data = henk_io get_line
put_line :: Data -> ()
Leaf FFI shared with IO. Writes output to console.
Implementationforeign put_line :: Data -> () = henk_io put_line
Functions
iof_put_line_f :: String -> S -> F r S
Helper to construct a "write" step in the interaction functor.
Implementationiof_put_line_f str ns x put_line_ get_line_ return_ = put_line_ str ns
iof_get_line_f :: (String -> S) -> F r S
Helper to construct a "read" step in the interaction functor.
Implementationiof_get_line_f k x put_line_ get_line_ return_ = get_line_ k
iof_return_f :: r -> F r S
Helper to construct a terminal step in the interaction functor.
Implementationiof_return_f vr x put_line_ get_line_ return_ = return_ vr
mk_io :: S -> (S -> F r S) -> IOI r
Creates an IOI process from an initial state and a step function (existential constructor).
Implementationmk_io r s seed step x k = k s seed step
run_ioi :: IOI r -> r
Unpacks the existential machine and drives the loop.
Implementationrun_ioi ioi = ioi Any (\_s -> \seed -> \step -> run_ioi_step seed step)