dstring 0.2 → 0.3
raw patch · 2 files changed
+49/−43 lines, 2 filesdep +to-string-classdep ~basePVP ok
version bump matches the API change (PVP)
Dependencies added: to-string-class
Dependency ranges changed: base
API changes (from Hackage documentation)
- Data.DString: append :: DString -> DString -> DString
- Data.DString: empty :: DString
- Data.DString: toString :: DString -> String
+ Data.DString: instance Show DString
+ Data.DString: instance ToString DString
Files
- Data/DString.hs +31/−27
- dstring.cabal +18/−16
Data/DString.hs view
@@ -1,12 +1,12 @@+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+ ----------------------------------------------------------------------------- -- | -- Module : Data.DString -- Copyright : (c) 2009 Bas van Dijk -- License : BSD-style (see the file LICENSE)--- -- Maintainer : Bas van Dijk <v.dijk.bas@gmail.com> -- Stability : experimental--- Portability : Only requires OverloadedStrings -- -- Difference strings: a data structure for O(1) append on -- strings. Note that a DString is just a newtype wrapper around a@@ -22,16 +22,13 @@ -- * Conversion , fromDList , toDList- , toString , fromShowS , toShowS -- * Basic functions- , empty , singleton , cons , snoc- , append , concat , list , head@@ -43,10 +40,15 @@ import Prelude hiding (concat, foldr, head, tail) import qualified Data.DList as D-import Data.Monoid-import Data.String+import Data.Monoid (Monoid)+import Data.String (IsString, fromString)+import qualified Data.String.ToString as ToString +--------------------------------------------------------------------------------+-- DString+--------------------------------------------------------------------------------+ -- | A difference string is a function that given a string, returns -- the original contents of the difference string prepended at the -- given string.@@ -72,24 +74,27 @@ -- > go (Leaf x) = "Leaf" <+> fromShow x -- > go (Branch l r) = "Branch" <+> paren (go l) <+> paren (go r) newtype DString = DS { toDList :: D.DList Char -- ^ Convert a difference string to a difference list- }---- | Convert a difference list of Chars to a difference string-fromDList :: D.DList Char -> DString-fromDList = DS--instance Monoid DString where- mempty = empty- mappend = append+ } deriving Monoid instance IsString DString where fromString = fromDList . D.fromList +instance ToString.ToString DString where+ toString = D.toList . toDList++instance Show DString where+ showsPrec p ds = showParen (p >= 10) $+ showString "Data.String.fromString " .+ shows (ToString.toString ds)+++-------------------------------------------------------------------------------- -- Conversions+-------------------------------------------------------------------------------- --- | Convert a difference string back to a normal String-toString :: DString -> String-toString = D.toList . toDList+-- | Convert a difference list of Chars to a difference string+fromDList :: D.DList Char -> DString+fromDList = DS -- | Convert a ShowS to a difference string fromShowS :: ShowS -> DString@@ -99,10 +104,11 @@ toShowS :: DString -> ShowS toShowS = D.unDL . toDList --- | Create a difference string containing no characters-empty :: DString-empty = fromDList D.empty +--------------------------------------------------------------------------------+-- Basic functions+--------------------------------------------------------------------------------+ -- | Build a difference string from a single Char singleton :: Char -> DString singleton = fromDList . D.singleton@@ -115,10 +121,6 @@ snoc :: DString -> Char -> DString snoc ds c = fromDList $ D.snoc (toDList ds) c --- | /O(1)/, Appending difference strings-append :: DString -> DString -> DString-x `append` y = fromDList (toDList x `D.append` toDList y)- -- | /O(spine)/, Concatenate difference strings concat :: [DString] -> DString concat = fromDList . D.concat . map toDList@@ -126,7 +128,7 @@ -- | /O(length ds)/, difference list elimination, head, tail. list :: b -> (Char -> DString -> b) -> DString -> b list nill consit ds =- case toString ds of+ case ToString.toString ds of [] -> nill x : xs -> consit x $ fromString xs @@ -146,3 +148,5 @@ foldr :: (Char -> b -> b) -> b -> DString -> b foldr f b = D.foldr f b . toDList ++-- The End ---------------------------------------------------------------------
dstring.cabal view
@@ -1,28 +1,30 @@-Name: dstring-Version: 0.2-Synopsis: Difference strings.+Name: dstring+Version: 0.3+Synopsis: Difference strings. Description: 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' so we can write overloaded string literals of type DString.--Category: Data-License: BSD3-License-file: LICENSE-Author: Bas van Dijk <v.dijk.bas@gmail.com>-Maintainer: Bas van Dijk <v.dijk.bas@gmail.com>-Copyright: 2009 Bas van Dijk <v.dijk.bas@gmail.com>-Cabal-version: >= 1.6-Build-Type: Simple-Stability: experimental+Category: Data+License: BSD3+License-file: LICENSE+Author: Bas van Dijk <v.dijk.bas@gmail.com>+Maintainer: Bas van Dijk <v.dijk.bas@gmail.com>+Copyright: 2009 Bas van Dijk <v.dijk.bas@gmail.com>+Cabal-version: >= 1.6+Build-Type: Simple+Stability: experimental+Extra-source-files: LICENSE Source-repository head Type: darcs Location: http://code.haskell.org/~basvandijk/code/dstring Library- Build-Depends: base, dlist- Exposed-modules: Data.DString- Ghc-options: -O2 -Wall+ Build-Depends: base == 4.*+ , dlist == 0.*+ , to-string-class == 0.*+ Exposed-modules: Data.DString+ Ghc-options: -O2 -Wall