diff --git a/Mainate.cabal b/Mainate.cabal index 5550508..2f65908 100644 --- a/Mainate.cabal +++ b/Mainate.cabal @@ -20,6 +20,7 @@ extra-source-files: CHANGELOG.md library exposed-modules: Graph , Stream + , Transducer , Tree -- other-modules: -- other-extensions: diff --git a/src/Transducer.hs b/src/Transducer.hs new file mode 100644 index 0000000..e3296e4 --- /dev/null +++ b/src/Transducer.hs @@ -0,0 +1,23 @@ +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