sorted-list 0.2.3.1 → 0.3.0.0
raw patch · 4 files changed
+38/−11 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.SortedList: instance (Test.QuickCheck.Arbitrary.Arbitrary a, GHC.Classes.Ord a) => Test.QuickCheck.Arbitrary.Arbitrary (Data.SortedList.SortedList a)
+ Data.SortedList: isSorted :: Ord a => SortedList a -> Bool
+ Data.SortedList: unsafeToSortedList :: [a] -> SortedList a
Files
- Data/SortedList.hs +28/−0
- changelog.md +6/−0
- sorted-list.cabal +3/−2
- tests/Main.hs +1/−9
Data/SortedList.hs view
@@ -5,6 +5,8 @@ -- with several functions to create and use values of that -- type. Many operations are optimized to take advantage -- of the list being sorted.+--+-- It is recommended to import this module qualified. module Data.SortedList ( -- * Type SortedList@@ -58,6 +60,10 @@ , nub , intersect , union+ -- * Unsafe+ , unsafeToSortedList+ -- * Testing+ , isSorted ) where import Prelude hiding@@ -96,18 +102,40 @@ #if !MIN_VERSION_base(4,18,0) import Control.Applicative (liftA2) #endif+-- QuickCheck+import Test.QuickCheck.Arbitrary (Arbitrary (..)) -- | Type of sorted lists. Any (non-bottom) value of this type -- is a sorted list. Use the 'Monoid' instance to merge sorted -- lists. newtype SortedList a = SortedList [a] deriving (Eq, Ord) +-- | Convert a regular list into a sorted list _without sorting it_.+-- By using this function, _you_ are responsible of ensuring that the+-- input is already sorted. If it's not, things will break badly.+unsafeToSortedList :: [a] -> SortedList a+unsafeToSortedList = SortedList++isListSorted :: Ord a => [a] -> Bool+isListSorted xs = and $ zipWith (<=) xs (tail xs)++-- | Check whether a sorted list is sorted.+-- Of course, this function should always return 'True'.+-- It's used mostly for testing.+isSorted :: Ord a => SortedList a -> Bool+{-# INLINE isSorted #-}+isSorted (SortedList xs) = isListSorted xs+ instance Show a => Show (SortedList a) where show = show . fromSortedList instance NFData a => NFData (SortedList a) where {-# INLINE rnf #-} rnf (SortedList xs) = rnf xs++instance (Arbitrary a, Ord a) => Arbitrary (SortedList a) where+ arbitrary = toSortedList <$> arbitrary+ shrink (SortedList xs) = toSortedList <$> shrink xs #if MIN_VERSION_base(4,7,0) instance Ord a => Exts.IsList (SortedList a) where
changelog.md view
@@ -1,3 +1,9 @@+## 0.3.0.0+* Add `Arbitrary` instance for `SortedList`.+ This added a library dependency on QuickCheck.+* Add function: `unsafeToSortedList`.+* Add function: `isSorted`.+ ## 0.2.3.1 * Extend support below base-4.18.
sorted-list.cabal view
@@ -1,5 +1,5 @@ name: sorted-list-version: 0.2.3.1+version: 0.3.0.0 synopsis: Type-enforced sorted lists and related functions. description: Type-enforced sorted lists and related functions. .@@ -36,9 +36,10 @@ library default-language: Haskell2010- ghc-options: -Wall+ ghc-options: -Wall -Wunused-packages build-depends: base == 4.* , deepseq+ , QuickCheck exposed-modules: Data.SortedList benchmark sorted-list-map-bench
tests/Main.hs view
@@ -1,13 +1,8 @@ -{-# OPTIONS_GHC -Wno-orphans #-}- module Main (main) where import Control.Monad (unless)-import Test.QuickCheck- ( Testable, isSuccess, quickCheckResult- , Arbitrary, arbitrary- )+import Test.QuickCheck (Testable, isSuccess, quickCheckResult) import System.Exit (exitFailure) import Data.SortedList (SortedList) import Data.SortedList qualified as SL@@ -19,9 +14,6 @@ putStrLn $ "Testing property: " ++ n r <- quickCheckResult p unless (isSuccess r) exitFailure--instance (Arbitrary a, Ord a) => Arbitrary (SortedList a) where- arbitrary = SL.toSortedList <$> arbitrary applyAsList :: Ord a => ([a] -> [a]) -> SortedList a -> SortedList a applyAsList f = SL.toSortedList . f . SL.fromSortedList