automata

Types

Automaton(state, symbol) represents a deterministic finite automaton: a current state, a transition function, and an acceptance predicate.

pub opaque type Automaton(state, symbol)

Values

pub fn accepts(
  automaton: Automaton(state, symbol),
  inputs: List(symbol),
) -> Bool

Return True when the automaton accepts the supplied input.

pub fn initial_state(
  automaton: Automaton(state, symbol),
) -> state

Return the initial state.

pub fn new(
  initial_state initial_state: state,
  transition transition: fn(state, symbol) -> state,
  accepting accepting: fn(state) -> Bool,
) -> Automaton(state, symbol)

Construct an automaton from its initial state, transition function, and acceptance predicate.

pub fn run(
  automaton: Automaton(state, symbol),
  inputs: List(symbol),
) -> state

Fold a list of input symbols over the automaton’s transition function and return the resulting state.

pub fn step(
  automaton: Automaton(state, symbol),
  state: state,
  symbol: symbol,
) -> state

Apply one transition from the supplied state using one input symbol.

Search Document