Commits

Bryan O'Sullivan  committed 66706a4

Rename invariant checks to be more descriptive.

  • Participants
  • Parent commits 5869952

Comments (0)

Files changed (1)

File Data/Text/Lazy/Internal.hs

     , foldrChunks
     , foldlChunks
     -- * Data type invariant and abstraction functions
-    , invariant
-    , checkInvariant
+
+    -- $invariant
+    , strictInvariant
+    , lazyInvariant
     , showStructure
+
     -- * Chunk allocation sizes
     , defaultChunkSize
     , smallChunkSize
           | Chunk {-# UNPACK #-} !T.Text Text
             deriving (Typeable)
 
--- | The data type invariant: Every 'Text' is either 'Empty' or
+-- $invariant
+--
+-- The data type invariant for lazy 'Text': Every 'Text' is either 'Empty' or
 -- consists of non-null 'T.Text's.  All functions must preserve this,
 -- and the QC properties must check this.
-invariant :: Text -> Bool
-invariant Empty                       = True
-invariant (Chunk (T.Text _ _ len) cs) = len > 0 && invariant cs
 
+-- | Check the invariant strictly.
+strictInvariant :: Text -> Bool
+strictInvariant Empty = True
+strictInvariant x@(Chunk (T.Text _ _ len) cs)
+    | len > 0   = strictInvariant cs
+    | otherwise = error $ "Data.Text.Lazy: invariant violation: "
+                  ++ showStructure x
+
+-- | Check the invariant lazily.
+lazyInvariant :: Text -> Text
+lazyInvariant Empty = Empty
+lazyInvariant x@(Chunk c@(T.Text _ _ len) cs)
+    | len > 0   = Chunk c (lazyInvariant cs)
+    | otherwise = error $ "Data.Text.Lazy: invariant violation: "
+                  ++ showStructure x
+
+-- | Display the internal structure of a lazy 'Text'.
 showStructure :: Text -> String
 showStructure Empty           = "Empty"
 showStructure (Chunk t Empty) = "Chunk " ++ show t ++ " Empty"
 showStructure (Chunk t ts)    =
     "Chunk " ++ show t ++ " (" ++ showStructure ts ++ ")"
 
--- | In a form that checks the invariant lazily.
-checkInvariant :: Text -> Text
-checkInvariant Empty = Empty
-checkInvariant (Chunk c@(T.Text _ _ len) cs)
-    | len > 0   = Chunk c (checkInvariant cs)
-    | otherwise = error $ "Data.Text.Lazy: invariant violation: "
-               ++ showStructure (Chunk c cs)
-
 -- | Smart constructor for 'Chunk'. Guarantees the data type invariant.
 chunk :: T.Text -> Text -> Text
 {-# INLINE chunk #-}