From d3f6fdc3ea71386c2b9a9cd5a686455dbee3e60e Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Mon, 21 May 2018 16:14:26 +0200 Subject: Introduce FSTs & Generalize input/output `toFST` is currently invalid --- edit-lens/src/Data/String/DFST.hs | 42 --------------------------------------- 1 file changed, 42 deletions(-) delete mode 100644 edit-lens/src/Data/String/DFST.hs (limited to 'edit-lens/src/Data/String/DFST.hs') diff --git a/edit-lens/src/Data/String/DFST.hs b/edit-lens/src/Data/String/DFST.hs deleted file mode 100644 index 54a1336..0000000 --- a/edit-lens/src/Data/String/DFST.hs +++ /dev/null @@ -1,42 +0,0 @@ -{-# LANGUAGE ScopedTypeVariables -#-} - -{-| -Description: Deterministic finite state transducers --} -module Data.String.DFST - ( DFST(..) - , runDFST, runDFST' - ) where - -import Data.Map.Strict (Map, (!?)) -import qualified Data.Map.Strict as Map - -import Data.Set (Set) -import qualified Data.Set as Set - -import Control.Monad - -data DFST state = DFST - { stInitial :: state - , stTransition :: Map (state, Char) (state, String) - -- ^ All @(s, c)@-combinations not mapped are assumed to map to @(s, Nothing)@ - , stAccept :: Set state - } - -runDFST :: forall state. Ord state => DFST state -> String -> Maybe String -runDFST dfst@DFST{..} str = let (finalState, str') = runDFST' dfst stInitial str id - in str' "" <$ guard (finalState `Set.member` stAccept) - -runDFST' :: forall state. Ord state - => DFST state - -> state -- ^ Current state - -> String -- ^ Remaining input - -> (String -> String) -- ^ Output as difference list - -> (state, (String -> String)) -- ^ Next state, altered output -runDFST' _ st [] acc = (st, acc) -runDFST' dfst@DFST{..} st (c:cs) acc - | Just (st', mc') <- stTransition !? (st, c) - = runDFST' dfst st' cs $ acc . (mc' ++) - | otherwise - = runDFST' dfst st cs acc -- cgit v1.2.3