dequeue 0.1.4 → 0.1.5
raw patch · 6 files changed
+86/−21 lines, 6 filessetup-changednew-component:exe:dequeue-testPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Data.Dequeue: instance (Arbitrary a) => Arbitrary (BankersDequeue a)
- Data.Dequeue: instance (Eq a) => Eq (BankersDequeue a)
- Data.Dequeue: instance (Show a) => Show (BankersDequeue a)
+ Data.Dequeue: instance Arbitrary a => Arbitrary (BankersDequeue a)
+ Data.Dequeue: instance Eq a => Eq (BankersDequeue a)
+ Data.Dequeue: instance Read a => Read (BankersDequeue a)
+ Data.Dequeue: instance Show a => Show (BankersDequeue a)
+ Data.Dequeue: prop_read_show_bq :: BankersDequeue Int -> Bool
+ Data.Dequeue: readDequeue :: (Dequeue q, Read a) => ReadS (Dequeue a) -> ReadS (q a)
+ Data.Dequeue: showDequeue :: (Foldable q, Dequeue q, Show a) => q a -> String
+ Data.Dequeue.Show: Dequeue :: [a] -> Dequeue a
+ Data.Dequeue.Show: instance Read a => Read (Dequeue a)
+ Data.Dequeue.Show: instance Show a => Show (Dequeue a)
+ Data.Dequeue.Show: newtype Dequeue a
- Data.Dequeue: empty :: (Dequeue q) => q a
+ Data.Dequeue: empty :: Dequeue q => q a
- Data.Dequeue: first :: (Dequeue q) => q a -> Maybe a
+ Data.Dequeue: first :: Dequeue q => q a -> Maybe a
- Data.Dequeue: fromList :: (Dequeue q) => [a] -> q a
+ Data.Dequeue: fromList :: Dequeue q => [a] -> q a
- Data.Dequeue: last :: (Dequeue q) => q a -> Maybe a
+ Data.Dequeue: last :: Dequeue q => q a -> Maybe a
- Data.Dequeue: length :: (Dequeue q) => q a -> Int
+ Data.Dequeue: length :: Dequeue q => q a -> Int
- Data.Dequeue: null :: (Dequeue q) => q a -> Bool
+ Data.Dequeue: null :: Dequeue q => q a -> Bool
- Data.Dequeue: popBack :: (Dequeue q) => q a -> (Maybe a, q a)
+ Data.Dequeue: popBack :: Dequeue q => q a -> (Maybe a, q a)
- Data.Dequeue: popFront :: (Dequeue q) => q a -> (Maybe a, q a)
+ Data.Dequeue: popFront :: Dequeue q => q a -> (Maybe a, q a)
- Data.Dequeue: pushBack :: (Dequeue q) => q a -> a -> q a
+ Data.Dequeue: pushBack :: Dequeue q => q a -> a -> q a
- Data.Dequeue: pushFront :: (Dequeue q) => q a -> a -> q a
+ Data.Dequeue: pushFront :: Dequeue q => q a -> a -> q a
- Data.Dequeue: takeBack :: (Dequeue q) => Int -> q a -> [a]
+ Data.Dequeue: takeBack :: Dequeue q => Int -> q a -> [a]
- Data.Dequeue: takeFront :: (Dequeue q) => Int -> q a -> [a]
+ Data.Dequeue: takeFront :: Dequeue q => Int -> q a -> [a]
Files
- Setup.hs +2/−0
- Setup.lhs +0/−7
- dequeue.cabal +17/−10
- src/Data/Dequeue.hs +47/−3
- src/Data/Dequeue/Show.hs +18/−0
- src/Tests.hs +2/−1
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
− Setup.lhs
@@ -1,7 +0,0 @@-#! /usr/bin/env runhaskell--> import Distribution.Simple-> import System.Cmd-> tests _ _ _ _ = system "runhaskell src/Tests.hs" >> return ()-> main = defaultMainWithHooks (simpleUserHooks {runTests = tests})-
dequeue.cabal view
@@ -1,7 +1,7 @@-Build-Type: Custom+Build-Type: Simple Name: dequeue Category: Data Structures-Version: 0.1.4+Version: 0.1.5 Cabal-Version: >= 1.2 Synopsis: A typeclass and an implementation for double-ended queues. Description:@@ -10,13 +10,20 @@ Structures. License: BSD3 License-File: LICENSE-Copyright: (c) 2009 Henry Bucklow+Copyright: (c) 2009-2010 Henry Bucklow Author: Henry Bucklow Maintainer: Henry Bucklow <henry@elsie.org.uk>-Tested-With: GHC==6.10-Build-Depends: base < 5, safe, QuickCheck-Exposed-Modules: Data.Dequeue-Hs-Source-Dirs: src-Extra-Source-Files: src/Tests.hs-GHC-Options: -Wall-Extensions: CPP+Tested-With: GHC==6.12++Library+ Exposed-Modules: Data.Dequeue, Data.Dequeue.Show+ Build-Depends: base < 5, safe, QuickCheck+ Hs-Source-Dirs: src+ GHC-Options: -Wall++Executable dequeue-test+ Buildable: False+ Main-Is: Tests.hs+ Hs-Source-Dirs: src+ Build-Depends: base < 5, QuickCheck+
src/Data/Dequeue.hs view
@@ -1,7 +1,8 @@+{-# LANGUAGE CPP #-} {- | Module : Data.Dequeue Description : A typeclass and an implementation for double-ended queues.-Copyright : (c) Henry Bucklow 2009+Copyright : (c) Henry Bucklow 2009-2010 License : BSD3 Maintainer : henry@elsie.org.uk@@ -14,6 +15,9 @@ module Data.Dequeue ( -- * The 'Dequeue' type class. Dequeue(..),+ -- * Support for 'Read' and 'Show' instances+ showDequeue,+ readDequeue, -- * QuickCheck properties for 'Dequeue' instances prop_pushpop_front, prop_pushpop_back,@@ -37,7 +41,8 @@ prop_push_front_bq_balance, prop_push_back_bq_balance, prop_pop_front_bq_balance,- prop_pop_back_bq_balance+ prop_pop_back_bq_balance,+ prop_read_show_bq ) where import Prelude hiding (foldl, foldr, foldl1, foldr1, length, last)@@ -54,6 +59,8 @@ import Safe +import qualified Data.Dequeue.Show+ -- | A typeclass for double-ended queues. class Dequeue q where -- | Generates an empty queue.@@ -83,6 +90,35 @@ -- | Converts a list into a queue. fromList :: [a] -> q a +-- | Support to make generating 'Show' instances for 'Dequeue's easier. Use as+-- follows:+--+-- @+-- instance Show a => Show (MyDequeue a) where+-- show q = showDequeue q+-- @+--+-- The resulting 'Show' instance will be portable between 'Deqeue' instances,+-- and will not expose the details of how your 'Dequeue' instance is+-- constructed.+showDequeue :: (Foldable q, Dequeue q, Show a) => q a -> String+showDequeue q = show $ Data.Dequeue.Show.Dequeue (toList q)++-- | Support to make generating 'Read' instances for 'Dequeue's easier. Use as+-- follows:+--+-- @+-- instance Read a => Read (MyDequeue a) where+-- readsPrec i = readDequeue $ readsPrec i+-- @+--+-- The resulting 'Read' instance will be portable between 'Deqeue' instances,+-- and will not expose the details of how your 'Dequeue' instance is+-- constructed.+readDequeue :: (Dequeue q, Read a) => ReadS (Data.Dequeue.Show.Dequeue a) -> ReadS (q a)+readDequeue readsDefn = \ s -> map convert (readsDefn s)+ where convert (Data.Dequeue.Show.Dequeue values, s) = (fromList values, s)+ -- QuickCheck properties for Dequeue instances. -- | Validates that if you push, then pop, the front of the queue,@@ -231,8 +267,11 @@ queue1 == queue2 = toList queue1 == toList queue2 instance Show a => Show (BankersDequeue a) where- show q = "BankersDequeue " ++ show (toList q)+ show q = showDequeue q +instance Read a => Read (BankersDequeue a) where+ readsPrec i = readDequeue $ readsPrec i+ -- QuickCheck properties for BankersDequeue. -- | Validates that if you push, then pop, the front of a 'BankersQueue',@@ -308,4 +347,9 @@ let pop _ queue = let (_, queue') = popBack queue in queue' q' = foldr pop q [0 .. count] in balanced q'++-- | Validates that a 'BankersDequeue' has read and show instances that are+-- the inverse of each other.+prop_read_show_bq :: BankersDequeue Int -> Bool+prop_read_show_bq q = (read . show) q == q
+ src/Data/Dequeue/Show.hs view
@@ -0,0 +1,18 @@+{- |+Module : Data.Dequeue.Show+Description : A newtype used entirely to provide 'Read' and 'Show' instances for 'Dequeue's.+Copyright : (c) Henry Bucklow 2010+License : BSD3++Maintainer : henry@elsie.org.uk+Stability : provisional+Portability : portable++A newtype used entirely for its derived 'Read' and 'Show' instances. These are+then used by 'showDequeue' and 'readDequeue' to make writing 'Read' and 'Show'+instances for 'Dequeue's easier.+-}+module Data.Dequeue.Show (Dequeue(..)) where++newtype Dequeue a = Dequeue [a] deriving (Read, Show)+
src/Tests.hs view
@@ -17,7 +17,8 @@ ("push_back_bq_balance", quickCheck prop_push_back_bq_balance), ("push_front_bq_balance", quickCheck prop_push_front_bq_balance), ("pop_front_bq_balance", quickCheck prop_pop_front_bq_balance),- ("pop_back_bq_balance", quickCheck prop_pop_back_bq_balance)]+ ("pop_back_bq_balance", quickCheck prop_pop_back_bq_balance),+ ("read_show_bq", quickCheck prop_read_show_bq)] main :: IO () main = mapM_ (\(s,a) -> printf "%-25s: " s >> a) tests