Add a new Transducer module built on the one for graphs
This commit is contained in:
parent
a8f87be2c1
commit
e562d0e605
2 changed files with 24 additions and 0 deletions
|
@ -20,6 +20,7 @@ extra-source-files: CHANGELOG.md
|
||||||
library
|
library
|
||||||
exposed-modules: Graph
|
exposed-modules: Graph
|
||||||
, Stream
|
, Stream
|
||||||
|
, Transducer
|
||||||
, Tree
|
, Tree
|
||||||
-- other-modules:
|
-- other-modules:
|
||||||
-- other-extensions:
|
-- other-extensions:
|
||||||
|
|
23
src/Transducer.hs
Normal file
23
src/Transducer.hs
Normal file
|
@ -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
|
Loading…
Reference in a new issue