peakachu-0.3.0: Experiemental library for composable interactive programs



Program a b is a pure representation of a computer program, which accepts inputs of type a, and outputs values of type b. It may also terminate. It can output zero or more b values after each a input.

  • A simple stateless input-output-loop can be created from a function with arrC.
  • A simple stateful input-output-loop can be created using scanlP.
  • Outputs can be filtered using filterC.

Programs may also be composed together in several ways using common type-classes

  • Category: Program a b -> Program b c -> Program a c. One program's outputs are fed to another program as input.
  • Monoid: Program a b -> Program a b -> Program a b. Both programs run in parallel processing the same input. Resulting Program outputs both's outputs.
  • Applicative: Program a (b -> c) -> Program a b -> Program a c.
  • Alternative MonadPlus: AppendProgram is a newtype wrapper whose Monoid instance runs one program after the other finishes (like ZipList offers an alternative Applicative instance for lists). It's also a Monad ant its monadic bind allows us to invoke inner programs based on an outer program's outputs.



data Program a b Source

A computer program




progVals :: [b]
progMore :: Maybe (a -> Program a b)

scanlP :: (b -> a -> b) -> b -> Program a bSource

Create a stateful input-output-loop from a simple function

emptyP :: Program a bSource

A program that terminates immediately

takeWhileP :: (a -> Bool) -> Program a aSource

Terminate when a predicate on input fails

loopbackP :: Program a (Either a b) -> Program a bSource

Feed some outputs of a Program to itself

singleValueP :: Program a ()Source

A program that outputs a value and immediately terminates

lstP :: (a -> Maybe b) -> Program a bSource

Given a partial function (a -> Maybe b), output its most recent result on an input.

lstPs :: Maybe b -> (a -> Maybe b) -> Program a bSource

Given a partial function (a -> Maybe b) and a start value, output its most recent result on an input.

delayP :: Integral i => i -> Program a aSource

Delay the outputs of a Program

withAppendProgram1 :: forall a0 b0 a1 b1. (AppendProgram a0 b0 -> AppendProgram a1 b1) -> Program a0 b0 -> Program a1 b1Source

withAppendProgram2 :: forall a0 b0 a1 b1 a2 b2. (AppendProgram a0 b0 -> AppendProgram a1 b1 -> AppendProgram a2 b2) -> Program a0 b0 -> Program a1 b1 -> Program a2 b2Source