From e562d0e6059fc385d1183f8f6d974e3ede6ad9f6 Mon Sep 17 00:00:00 2001 From: Tissevert Date: Mon, 6 May 2019 08:21:50 +0200 Subject: [PATCH] Add a new Transducer module built on the one for graphs --- Mainate.cabal | 1 + src/Transducer.hs | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 src/Transducer.hs 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