dlist 0.3.1 → 0.3.2
raw patch · 3 files changed
+44/−13 lines, 3 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Data.DList: data DList a
+ Data.DList: DL :: ([a] -> [a]) -> DList a
+ Data.DList: instance Applicative DList
+ Data.DList: newtype DList a
+ Data.DList: unDL :: DList a -> [a] -> [a]
Files
- Data/DList.hs +31/−8
- dlist.cabal +11/−5
- tests/Properties.hs +2/−0
Data/DList.hs view
@@ -14,7 +14,7 @@ module Data.DList ( - DList -- abstract, instance Monoid, Functor, Monad, MonadPlus+ DList(..) -- abstract, instance Monoid, Functor, Applicative, Monad, MonadPlus -- * Construction ,fromList -- :: [a] -> DList a@@ -40,15 +40,32 @@ ) where import Prelude hiding (concat, foldr, map, head, tail)+import qualified Data.List as List import Control.Monad-import qualified Data.List as List (concat, foldr, map, unfoldr)+import Control.Applicative(Applicative(..)) import Data.Monoid -- | A difference list is a function that given a list, returns the -- original contents of the difference list prepended at the given list ----- This structure supports /O(1)/ append and snoc operations on lists.+-- This structure supports /O(1)/ append and snoc operations on lists,+-- making it very useful for append-heavy uses, such as logging and+-- pretty printing. --+-- For example, using DList as the state type when printing a tree with+-- the Writer monad+--+-- > import Control.Monad.Writer+-- > import Data.DList+-- > +-- > data Tree a = Leaf a | Branch (Tree a) (Tree a)+-- >+-- > flatten_writer :: Tree x -> DList x+-- > flatten_writer = snd . runWriter . flatten+-- > where+-- > flatten (Leaf x) = tell (singleton x)+-- > flatten (Branch x y) = flatten x >> flatten y+-- newtype DList a = DL { unDL :: [a] -> [a] } -- | Converting a normal list to a dlist@@ -95,10 +112,10 @@ -- | /O(length dl)/, List elimination, head, tail. list :: b -> (a -> DList a -> b) -> DList a -> b-list null cons dl =+list nill consit dl = case toList dl of- [] -> null- (x : xs) -> cons x (fromList xs)+ [] -> nill+ (x : xs) -> consit x (fromList xs) -- | Return the head of the list head :: DList a -> a@@ -113,7 +130,7 @@ unfoldr pf b = case pf b of Nothing -> empty- Just (a, b) -> cons a (unfoldr pf b)+ Just (a, b') -> cons a (unfoldr pf b') -- | Foldr over difference lists foldr :: (a -> b -> b) -> b -> DList a -> b@@ -133,6 +150,12 @@ fmap = map {-# INLINE fmap #-} +#if __GLASGOW_HASKELL__ >= 608+instance Applicative DList where+ pure = return+ (<*>) = ap+#endif+ instance Monad DList where m >>= k -- = concat (toList (fmap k m))@@ -146,7 +169,7 @@ return x = singleton x {-# INLINE return #-} - fail s = empty+ fail _ = empty {-# INLINE fail #-} instance MonadPlus DList where
dlist.cabal view
@@ -1,14 +1,20 @@ Name: dlist-Version: 0.3.1+Version: 0.3.2 Synopsis: Differences lists-Description: Differences lists: a list-like type supporting O(1) append+Description: + Differences lists: a list-like type supporting O(1) append.+ This is particularly useful for efficient logging and pretty+ printing, (e.g. with the Writer monad), where list append + quickly becomes too expensive. Category: Data License: BSD3 License-file: LICENSE Author: Don Stewart -Maintainer: dons@cse.unsw.edu.au+Maintainer: dons@galois.com+Copyright: 2006-7 Don Stewart+Homepage: http://www.cse.unsw.edu.au/~dons/dlist.html Build-Depends: base-Ghc-options: -O2+Ghc-options: -O2 -Wall+Extensions: CPP Exposed-modules: Data.DList-Homepage: http://www.cse.unsw.edu.au/~dons/dlist.html extra-source-files: README tests/Properties.hs tests/Parallel.hs
tests/Properties.hs view
@@ -72,7 +72,9 @@ -- missing QC instances -- +{- instance Arbitrary a => Arbitrary (Maybe a) where arbitrary = do a <- arbitrary ; elements [Nothing, Just a] coarbitrary Nothing = variant 0 coarbitrary _ = variant 1 -- ok?+ -}