algebraic-graphs-0.6.1: 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 HaskellNone
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 Source #

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

data State Source #

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 Source # 
Instance details

Defined in Algebra.Graph.Labelled.Example.Automaton

Enum State Source # 
Instance details

Defined in Algebra.Graph.Labelled.Example.Automaton

Eq State Source # 
Instance details

Defined in Algebra.Graph.Labelled.Example.Automaton

Methods

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

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

Ord State Source # 
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 #

Show State Source # 
Instance details

Defined in Algebra.Graph.Labelled.Example.Automaton

Methods

showsPrec :: Int -> State -> ShowS #

show :: State -> String #

showList :: [State] -> ShowS #

coffeeTeaAutomaton :: Automaton Alphabet State Source #

An example automaton for ordering coffee or tea.

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

reachability :: Map State [State] Source #

The map of State reachability.

reachability = Map.fromList $ map (s -> (s, reachable s order)) [Choice ..]

Or, when evaluated:

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