-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Difference strings -- -- Difference strings: a data structure for O(1) append on strings. Note -- that a DString is just a newtype wrapper around a DList -- Char. The reason we need a new type instead of just a type -- synonym is that we can have an instance IsString DString -- without using language extensions (TypeSynonymInstances or -- FlexibleInstances) so we can write overloaded string literals -- of type DString. @package dstring @version 0.3.0.2 -- | Difference strings: a data structure for O(1) append on strings. Note -- that a DString is just a newtype wrapper around a DList -- Char. The reason we need a new type instead of just a type -- synonym is that we can have an instance IsString -- DString without using language extensions -- (TypeSynonymInstances or FlexibleInstances) so we -- can write overloaded string literals of type DString. module Data.DString -- | A difference string is a function that given a string, returns the -- original contents of the difference string prepended at the given -- string. -- -- This structure supports O(1) mappend en snoc -- operations on strings making it very usefull for append-heavy uses -- such as logging and pretty printing. -- -- You can use it to efficiently show a tree for example: (Note that we -- use some handy functions from the string-combinators package) -- --
-- {-# LANGUAGE OverloadedStrings #-}
--
-- import Data.DString (toShowS, fromShowS)
-- import Data.String.Combinators ((<+>), paren)
--
-- data Tree a = Leaf a | Branch (Tree a) (Tree a)
--
-- instance Show a => Show (Tree a) where
-- showsPrec prec = showParen (prec >= funAppPrec) . toShowS . go
-- where
-- go (Leaf x) = "Leaf" <+> fromShowS (showsPrec funAppPrec x)
-- go (Branch l r) = "Branch" <+> paren (go l) <+> paren (go r)
--
-- funAppPrec = 10
--
--
-- Note that a DString can be converted from and to a
-- String using the fromString and toString
-- methods from the IsString and ToString classes
-- respectively.
data DString
-- | O(1) Convert a difference list of Chars to a difference
-- string.
fromDList :: DList Char -> DString
-- | O(1) Convert a difference string to a difference list.
toDList :: DString -> DList Char
-- | O(1) Convert a ShowS to a difference string.
fromShowS :: ShowS -> DString
-- | O(1) Convert a difference string to a ShowS.
toShowS :: DString -> ShowS
-- | O(1) Build a difference string from a single Char.
singleton :: Char -> DString
-- | O(1), Prepend a Char to a difference string.
cons :: Char -> DString -> DString
-- | O(1), Append a Char to a difference string.
snoc :: DString -> Char -> DString
-- | O(spine), Concatenate difference strings.
concat :: [DString] -> DString
-- | O(length ds), difference list elimination, head, tail.
list :: α -> (Char -> DString -> α) -> DString -> α
-- | Return the head of the difference string.
head :: DString -> Char
-- | Return the tail of the difference string.
tail :: DString -> DString
-- | Unfoldr for difference strings.
unfoldr :: (α -> Maybe (Char, α)) -> α -> DString
-- | Foldr over difference strings.
foldr :: (Char -> α -> α) -> α -> DString -> α
instance Typeable DString
instance Monoid DString
instance Show DString
instance ToString DString
instance IsString DString