Commits

Eric Rochester committed 2d02acd

Added RuleBody, Data.Sequence.Seq, and functions for basic Sequitur operations.

  • Participants
  • Parent commits 8d18833

Comments (0)

Files changed (3)

File Data.Sequitur.cabal

 Executable testSequitur
   main-is:       Test/Main.hs
   build-depends: base
+               , containers
                , Cabal>=1.2
                , QuickCheck
                , HUnit

File Test/SequiturUnit.hs

 module Test.SequiturUnit (tests, runTests) where
 
 import Test.HUnit
+import Data.Foldable (toList)
+import qualified Data.Sequence as S
 import qualified Data.Sequitur as Seq
 
 
 testRule :: Seq.Compressor Char -> Integer -> [Seq.Symbol Char] -> Assertion
 testRule compressor name expected =
-    assertEqual title expected actual
-    where actual = Seq.rule compressor name
-          title  = (show name) ++ " ->"
+    assertEqual title expList actual
+    where actual  = toList $ Seq.rule compressor name
+          expList = expected
+          title   = (show name) ++ " ->"
 
 test_abcdbc = TestCase (do
     let compressed = Seq.compress "abcdbc"
 -- This test actually has two valid outcomes.
 test_aabaaab = TestCase (do
     let compressed = Seq.compress "aabaaab"
-    case (Seq.rule compressed 0) of
+    case (toList $ Seq.rule compressed 0) of
         [ Seq.Rule 1, Seq.Literal 'a', Seq.Rule 1 ] ->
             testRule compressed 1 [ Seq.Literal 'a'
                                   , Seq.Literal 'a'

File src/Data/Sequitur.hs

 
 import Prelude hiding (init)
 import qualified Data.Map as M
+import qualified Data.Sequence as S
 
 -- Operations:
 --  * appending a symbol to rule S;
     | Rule Integer      -- A rule.
     deriving (Show, Eq)
 
+-- | This is a rule's body
+type RuleBody a = S.Seq (Symbol a)
+
 -- | This is the compressor data types.
 data Compressor a = Compressor {
-      rules     :: M.Map Integer [Symbol a]     -- The list of rules defined.
+      rules     :: M.Map Integer (RuleBody a)       -- The list of rules defined.
     , ruleCount :: Integer                      -- The number of rules defined.
     }
 
+-- | This serializes a 
+
 -- | This returns the rule of a given number.
-rule :: Eq a => Compressor a -> Integer -> [Symbol a]
+rule :: Eq a => Compressor a -> Integer -> RuleBody a
 rule compressor key =
-    M.findWithDefault [] key $ rules compressor
+    M.findWithDefault S.empty key $ rules compressor
 
 -- | This returns a new, empty compressor.
 init :: Compressor a
 feed :: Eq a => Compressor a -> a -> Compressor a
 feed compressor _ = compressor
 
+-- | This appends a symbol to a rule.
+append :: Eq a => Compressor a -> Integer -> a -> Compressor a
+append compressor _ _ = compressor
+
+-- | This uses an existing rule.
+use :: Compressor a -> Integer -> Compressor a
+use compressor _ = compressor
+
+-- | This creates a new rule.
+create :: Compressor a -> (Integer, Compressor a)
+create compressor = (0, compressor)
+
+-- | This deletes a rule.
+delete :: Compressor a -> Integer -> Compressor a
+delete compressor _ = compressor
+