summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2018-02-04 17:39:46 +0100
committerGregor Kleen <gkleen@yggdrasil.li>2018-02-04 17:39:46 +0100
commit529d127667a366f306f975b3ed34e8a118f3cefc (patch)
tree01be59b0bfbe21e3691e81cf08bcfe39f0be08ee
parent3439c87294a7e25cea88632cdcc0630d4f3746bc (diff)
downloadincremental-dfsts-529d127667a366f306f975b3ed34e8a118f3cefc.tar
incremental-dfsts-529d127667a366f306f975b3ed34e8a118f3cefc.tar.gz
incremental-dfsts-529d127667a366f306f975b3ed34e8a118f3cefc.tar.bz2
incremental-dfsts-529d127667a366f306f975b3ed34e8a118f3cefc.tar.xz
incremental-dfsts-529d127667a366f306f975b3ed34e8a118f3cefc.zip
Define DFSTs
-rw-r--r--edit-lens/package.yaml4
-rw-r--r--edit-lens/src/Data/String/DFST.hs38
-rw-r--r--stack.yaml2
-rw-r--r--thesis.tex1
4 files changed, 42 insertions, 3 deletions
diff --git a/edit-lens/package.yaml b/edit-lens/package.yaml
index db1f021..5e8c2d2 100644
--- a/edit-lens/package.yaml
+++ b/edit-lens/package.yaml
@@ -23,8 +23,10 @@ library:
23 dependencies: 23 dependencies:
24 - base 24 - base
25 - lens 25 - lens
26 - containers
26 exposed-modules: 27 exposed-modules:
27 - Control.Edit 28 - Control.Edit
28 - Control.Edit.Tree 29 - Data.String.DFST
29 - Control.Lens.Edit 30 - Control.Lens.Edit
31
30 32
diff --git a/edit-lens/src/Data/String/DFST.hs b/edit-lens/src/Data/String/DFST.hs
new file mode 100644
index 0000000..8a22dd3
--- /dev/null
+++ b/edit-lens/src/Data/String/DFST.hs
@@ -0,0 +1,38 @@
1{-# LANGUAGE RecordWildCards
2 , PatternGuards
3 , ScopedTypeVariables
4#-}
5
6{-|
7Description: Deterministic finite state transducers
8-}
9module Data.String.DFST
10 ( DFST(..)
11 , runDFST
12 ) where
13
14import Data.Map.Strict (Map, (!?))
15import qualified Data.Map.Strict as Map
16
17import Data.Set (Set)
18import qualified Data.Set as Set
19
20data DFST state = DFST
21 { stInitial :: state
22 , stTransition :: Map (state, Char) (state, Maybe Char)
23 -- ^ All @(s, c)@-combinations not mapped are assumed to map to @(s, Nothing)@
24 , stAccept :: Set state
25 }
26
27runDFST :: forall state. Ord state => DFST state -> String -> Maybe String
28runDFST DFST{..} str = ($ []) <$> go stInitial str id
29 where
30 go :: state -> String -> (String -> String) -> Maybe (String -> String)
31 go st [] acc
32 | st `Set.member` stAccept = Just acc
33 | otherwise = Nothing
34 go st (c:cs) acc
35 | Just (st', mc') <- stTransition !? (st, c)
36 = go st' cs $ acc . maybe id (:) mc'
37 | otherwise
38 = go st cs acc
diff --git a/stack.yaml b/stack.yaml
index 125d9fb..2e6ea32 100644
--- a/stack.yaml
+++ b/stack.yaml
@@ -1,4 +1,4 @@
1resolver: lts-9.9 1resolver: lts-10.4
2packages: 2packages:
3 - edit-lens 3 - edit-lens
4nix: 4nix:
diff --git a/thesis.tex b/thesis.tex
index f975ba7..6b94318 100644
--- a/thesis.tex
+++ b/thesis.tex
@@ -3,4 +3,3 @@ Dabei werden wir die Definitionen aus \cite{hofmann2012edit} sowohl in natürlic
3 3
4\input{./edit-lens/src/Control/Edit.lhs} 4\input{./edit-lens/src/Control/Edit.lhs}
5\input{./edit-lens/src/Control/Lens/Edit.lhs} 5\input{./edit-lens/src/Control/Lens/Edit.lhs}
6\input{./edit-lens/src/Control/Edit/Tree.lhs}