-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Write your main like it can call itself back. -- -- Please see the README on GitHub at -- https://github.com/githubuser/corecursive-main#readme @package corecursive-main @version 0.1.0.0 -- | 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) module System.Process.Corecursive.Base -- | 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. data App t msg arg inst ret App :: msg -> t arg -> arg -> t msg -> Self t msg arg inst -> arg -> t ret -> App t msg arg inst ret -- | Function parsing argument from a serialized message. [parseArgs] :: App t msg arg inst ret -> msg -> t arg -- | Function un-parsing an argument into a serialized message. [unparseArgs] :: App t msg arg inst ret -> arg -> t msg -- | Actual program to run from a specification. [corecursiveProgram] :: App t msg arg inst ret -> Self t msg arg inst -> arg -> t ret -- | Constructor for an App. app :: (msg -> m arg) -> (arg -> m msg) -> (Self m msg arg inst -> arg -> m ret) -> App m msg arg inst ret -- | Typical function to run an App with simplifying assumptions: -- -- runApp :: Monad m => m inst -> m msg -> App m msg arg inst ret -> m ret -- | 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. data Self t msg arg inst Self :: t inst -> arg -> t msg -> Self t msg arg 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. [executable] :: Self t msg arg inst -> t inst -- | An action to unparse arguments. Typically from unparseArgs. [unparse] :: Self t msg arg inst -> arg -> t msg instance GHC.Base.Functor t => GHC.Base.Functor (System.Process.Corecursive.Base.App t msg arg inst) instance GHC.Base.Functor t => GHC.Base.Functor (System.Process.Corecursive.Base.Self t msg arg) -- | A module to facilitate and demonstrate a programming pattern where -- application instances for a system is (co-)recursive. module System.Process.Corecursive -- | Run function for an App which arguments are read from the command line -- using getArgs and for which the binary is discovered from -- getExecutablePath. runCorecursiveApp :: MonadIO m => App m [String] arg FilePath () -> m () -- | Callback running the Self executable locally and waiting until -- completion using callProcess. callback :: MonadIO m => Self m [String] arg FilePath -> arg -> m () -- | Callback running the Self executable locally and waiting until -- completion using readProcess. readCallback :: MonadIO m => Self m [String] arg FilePath -> arg -> m String -- | 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. data App t msg arg inst ret -- | 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. data Self t msg arg inst -- | Constructor for an App. app :: (msg -> m arg) -> (arg -> m msg) -> (Self m msg arg inst -> arg -> m ret) -> App m msg arg inst ret