24 lines
649 B
Haskell
24 lines
649 B
Haskell
|
module Transducer (
|
||
|
Transducer
|
||
|
, fromList
|
||
|
, run
|
||
|
) where
|
||
|
|
||
|
import Stream (Stream)
|
||
|
import Graph (Graph, editLabel, open, rewind, singleton, weave)
|
||
|
|
||
|
type Transducer input output = Graph input [output]
|
||
|
|
||
|
empty :: Transducer input output
|
||
|
empty = open $ singleton []
|
||
|
|
||
|
add :: Ord input => Transducer input output -> ([input], output) -> Transducer input output
|
||
|
add transducer (path, output) =
|
||
|
rewind $ editLabel (weave transducer path) (output:)
|
||
|
|
||
|
fromList :: Ord input => [([input], output)] -> Transducer input output
|
||
|
fromList = foldl add empty
|
||
|
|
||
|
run :: Ord input => Transducer input output -> Stream input -> Stream output
|
||
|
run = undefined
|