The main module of the marionette runtime. You need a Controller and a Renderer in addition to the types and functions that are defined in here to run a state machine program.

#Config Source

type Config msg sta = { exitIf :: msg -> sta -> Boolean, initialMsg :: Maybe msg, onEvent :: ProgramEvent msg sta -> Effect Unit, stateHandler :: sta -> Effect (State sta Aff) }

Type variables:

  • msg the message type of your program
  • sta the state type of your program

Record fields:

  • exitIf provides an exit condition to leave the running state machine based on the current message/state combination.
  • initialMsg useful if the first message event is not triggered by user input.
  • onEvent lets you observe events that occur inside the marionette runtime. This is useful for either debugging or other kind of state machine flow analysis.
  • stateHandler The state implementation that is used by the runtime.

#EventType Source

data EventType msg sta

Possible observable events that may occur inside the marionette runtime.


  • NewMsg ThreadId msg

    new thread is triggered by a message event

  • EndMsg ThreadId

    specific thread triggered by a message event has finished running

  • NewState ThreadId sta

    new state update has been performed and a re-rendering was triggered


#Program Source

type Program msg sta = { controller :: Controller msg sta, initialState :: sta, renderer :: Renderer msg sta }

Type variables:

  • msg message type of your program
  • sta state type of your program

Record fields:

  • initialState value of the initial state
  • renderer specifies how state is rendered
  • controller specifies the how the control flow is handled

#ProgramEvent Source

data ProgramEvent msg sta

General program event type that contains a timestamp and a more specific event type.



#ThreadId Source

newtype ThreadId

Every time a message is raised a new thread with an unique ThreadId is created that has read and write access to the program's state.



#defaultConfig Source

defaultConfig :: forall msg sta. Eq sta => Config msg sta

Some defaults for the Config type

#noController Source

noController :: forall msg sta. Controller msg sta

A controller that does nothing. Useful if you just want to render something and the controller is not implemented yet.

#noRenderer Source

noRenderer :: forall msg sta. Renderer msg sta

A renderer that does nothing. Useful if like to run a headless state machine.

#runProgram Source

runProgram :: forall msg sta. Eq sta => Program msg sta -> Config msg sta -> Aff sta

Takes a stateful program specification and some configuration and runs the program in an Aff context.

Once the program has finished the final state is returned and all running threads are aborted.