algebraic-graphs-0.7: A library for algebraic graph construction and transformation
Copyright(c) Andrey Mokhov 2016-2022
LicenseMIT (see the file LICENSE)
Maintainerandrey.mokhov@gmail.com
Stabilityexperimental
Safe HaskellSafe-Inferred
LanguageHaskell2010

Algebra.Graph.Labelled.Example.Automaton

Description

Alga is a library for algebraic construction and manipulation of graphs in Haskell. See this paper for the motivation behind the library, the underlying theory, and implementation details.

This module contains a simple example of using edge-labelled graphs defined in the module Algebra.Graph.Labelled for working with finite automata.

Synopsis

Documentation

data Alphabet #

The alphabet of actions for ordering coffee or tea.

Constructors

Coffee

Order coffee

Tea

Order tea

Cancel

Cancel payment or order

Pay

Pay for the order

Instances

Instances details
Bounded Alphabet # 
Instance details

Defined in Algebra.Graph.Labelled.Example.Automaton

Enum Alphabet # 
Instance details

Defined in Algebra.Graph.Labelled.Example.Automaton

Show Alphabet # 
Instance details

Defined in Algebra.Graph.Labelled.Example.Automaton

Methods

showsPrec :: Int -> Alphabet -> ShowS

show :: Alphabet -> String

showList :: [Alphabet] -> ShowS

Eq Alphabet # 
Instance details

Defined in Algebra.Graph.Labelled.Example.Automaton

Methods

(==) :: Alphabet -> Alphabet -> Bool

(/=) :: Alphabet -> Alphabet -> Bool

Ord Alphabet # 
Instance details

Defined in Algebra.Graph.Labelled.Example.Automaton

Methods

compare :: Alphabet -> Alphabet -> Ordering

(<) :: Alphabet -> Alphabet -> Bool

(<=) :: Alphabet -> Alphabet -> Bool

(>) :: Alphabet -> Alphabet -> Bool

(>=) :: Alphabet -> Alphabet -> Bool

max :: Alphabet -> Alphabet -> Alphabet

min :: Alphabet -> Alphabet -> Alphabet

data State #

The state of the order.

Constructors

Choice

Choosing what to order

Payment

Making the payment

Complete

The order is complete

Instances

Instances details
Bounded State # 
Instance details

Defined in Algebra.Graph.Labelled.Example.Automaton

Enum State # 
Instance details

Defined in Algebra.Graph.Labelled.Example.Automaton

Show State # 
Instance details

Defined in Algebra.Graph.Labelled.Example.Automaton

Methods

showsPrec :: Int -> State -> ShowS

show :: State -> String

showList :: [State] -> ShowS

Eq State # 
Instance details

Defined in Algebra.Graph.Labelled.Example.Automaton

Methods

(==) :: State -> State -> Bool

(/=) :: State -> State -> Bool

Ord State # 
Instance details

Defined in Algebra.Graph.Labelled.Example.Automaton

Methods

compare :: State -> State -> Ordering

(<) :: State -> State -> Bool

(<=) :: State -> State -> Bool

(>) :: State -> State -> Bool

(>=) :: State -> State -> Bool

max :: State -> State -> State

min :: State -> State -> State

coffeeTeaAutomaton :: Automaton Alphabet State #

An example automaton for ordering coffee or tea.

coffeeTeaAutomaton = overlays [ Choice  -<[Coffee, Tea]>- Payment
                              , Payment -<[Pay        ]>- Complete
                              , Choice  -<[Cancel     ]>- Complete
                              , Payment -<[Cancel     ]>- Choice ]

reachability :: Map State [State] #

The map of State reachability.

reachability = Map.fromList $ map (id &&& reachable skeleton) [Choice ..]
  where
    skeleton = emap (Any . not . isZero) coffeeTeaAutomaton

Or, when evaluated:

reachability = Map.fromList [ (Choice  , [Choice  , Payment, Complete])
                            , (Payment , [Payment , Choice , Complete])
                            , (Complete, [Complete                   ]) ]