corecursive-main-0.1.0.0: Write your main like it can call itself back.

Safe HaskellSafe
LanguageHaskell2010

System.Process.Corecursive.Base

Description

Types for building (co-)recursive system programs.

The tools in this module allow to define the call-site and the main entry point of a (co-)recursive program.

However, this module does not define callback usages so that implementers are free to chose the mechanism they want to: - start the recursive program - retrieve a return-value (if the recursive program ever returns)

Synopsis

Documentation

data App t msg arg inst ret Source #

A datatype wrapping everything needed to make a (co-)recursive main function.

Application authors may find this type useful because it has a Functor instance, allowing to adapt the result of a computation.

See app.

Constructors

App 

Fields

  • parseArgs :: msg -> t arg

    Function parsing argument from a serialized message.

  • unparseArgs :: arg -> t msg

    Function un-parsing an argument into a serialized message.

  • corecursiveProgram :: Self t msg arg inst -> arg -> t ret

    Actual program to run from a specification.

Instances
Functor t => Functor (App t msg arg inst) Source # 
Instance details

Defined in System.Process.Corecursive.Base

Methods

fmap :: (a -> b) -> App t msg arg inst a -> App t msg arg inst b #

(<$) :: a -> App t msg arg inst b -> App t msg arg inst a #

app Source #

Arguments

:: (msg -> m arg)

Function parsing argument from a serialized message.

-> (arg -> m msg)

Function un-parsing an argument into a serialized message.

-> (Self m msg arg inst -> arg -> m ret)

Actual program to run from a specification.

-> App m msg arg inst ret 

Constructor for an App.

runApp Source #

Arguments

:: Monad m 
=> m inst

An action to locate the self instance of an applictaion. This action is run exactly once and the result is stored in Self.

-> m msg

An action to retrieve the message to start the application with. This action is run exactly once, the result is then parsed and discarded.

-> App m msg arg inst ret

The App to run

-> m ret 

Typical function to run an App with simplifying assumptions:

  • locate the Self instance once for the rest of the program
  • reads the arguments once
  • starts the actual program

data Self t msg arg inst Source #

A datatype representing an instance of the (co-)recursive program.

A reason why the records in this type are separate from App is that a calling program may need to execute a fair amount of progress before knowing the right executable (e.g., in the case of a remote invocation). Also, sometimes one may want to adapt Self.

Constructors

Self 

Fields

  • executable :: t inst

    An action to retrieve an instance of the (co-)recursive program the inst type is leaved as an argument to allow representing cases where the execution is actually remote.

  • unparse :: arg -> t msg

    An action to unparse arguments. Typically from unparseArgs.

Instances
Functor t => Functor (Self t msg arg) Source # 
Instance details

Defined in System.Process.Corecursive.Base

Methods

fmap :: (a -> b) -> Self t msg arg a -> Self t msg arg b #

(<$) :: a -> Self t msg arg b -> Self t msg arg a #