AFSM-0.1.2.0: Arrowized functional state machines

Copyright(c) Hanzhong Xu Meng Meng 2016
LicenseMIT License
Maintainerhanzh.xu@gmail.com
Stabilityexperimental
Portabilityportable
Safe HaskellSafe
LanguageHaskell2010

Control.AFSM

Contents

Description

Arrowized functional state machines.

This module is inspired by Yampa and the paper Functional Reactive Programming, Continued* written by Henrik Nilsson, Antony Courtney and John Peterson.

Synopsis

Documentation

data Event a Source #

Event type, there are 4 different events: event a, no event, error event string and exit event.

Instances

Eq a => Eq (Event a) Source # 

Methods

(==) :: Event a -> Event a -> Bool #

(/=) :: Event a -> Event a -> Bool #

Ord a => Ord (Event a) Source # 

Methods

compare :: Event a -> Event a -> Ordering #

(<) :: Event a -> Event a -> Bool #

(<=) :: Event a -> Event a -> Bool #

(>) :: Event a -> Event a -> Bool #

(>=) :: Event a -> Event a -> Bool #

max :: Event a -> Event a -> Event a #

min :: Event a -> Event a -> Event a #

Show a => Show (Event a) Source # 

Methods

showsPrec :: Int -> Event a -> ShowS #

show :: Event a -> String #

showList :: [Event a] -> ShowS #

The SM type

data SM a b Source #

SM is a type representing a state machine.

Instances

Arrow SM Source # 

Methods

arr :: (b -> c) -> SM b c #

first :: SM b c -> SM (b, d) (c, d) #

second :: SM b c -> SM (d, b) (d, c) #

(***) :: SM b c -> SM b' c' -> SM (b, b') (c, c') #

(&&&) :: SM b c -> SM b c' -> SM b (c, c') #

ArrowChoice SM Source # 

Methods

left :: SM b c -> SM (Either b d) (Either c d) #

right :: SM b c -> SM (Either d b) (Either d c) #

(+++) :: SM b c -> SM b' c' -> SM (Either b b') (Either c c') #

(|||) :: SM b d -> SM c d -> SM (Either b c) d #

ArrowApply SM Source # 

Methods

app :: SM (SM b c, b) c #

ArrowLoop SM Source # 

Methods

loop :: SM (b, d) (c, d) -> SM b c #

Functor (SM a) Source # 

Methods

fmap :: (a -> b) -> SM a a -> SM a b #

(<$) :: a -> SM a b -> SM a a #

Category * SM Source # 

Methods

id :: cat a a #

(.) :: cat b c -> cat a b -> cat a c #

The SMState type

type SMState s a b = s -> a -> (SM a b, b) Source #

SMState is the transition function s: storage, a: input, b: output

Constructors

newSM :: SMState s a b -> s -> SM a b Source #

It is the same with the SM constructor.

simpleSM :: (s -> a -> (s, b)) -> s -> SM a b Source #

build a simple SM which have only one SMState.

Basic State Machines

constSM :: b -> SM a b Source #

build a SM which always return b

idSM :: SM a a Source #

foldlSM :: (s -> a -> s) -> s -> SM a s Source #

the same with foldl

foldlDelaySM :: (s -> a -> s) -> s -> SM a s Source #

the difference from foldlSM is it output the storage first.

delaySM :: a -> SM a a Source #

delay the input with given value. delaySM = foldlDelaySM (const id)

High order functions

execSM :: SM a b -> SM [a] [b] Source #

converts SM a b -> SM [a] [b], it is very useful to compose SM a [b] and SM b c to SM a [c].

concatSM :: SM a [[b]] -> SM a [b] Source #

Evaluation

exec :: SM a b -> [a] -> (SM a b, [b]) Source #

execute SM a b with input [a].