utility-ht 0.0.15 → 0.0.16
raw patch · 31 files changed
+1685/−685 lines, 31 filesdep +doctest-exitcode-stdiodep +doctest-lib
Dependencies added: doctest-exitcode-stdio, doctest-lib
Files
- Makefile +18/−0
- src/Data/Bool/HT/Private.hs +8/−2
- src/Data/Either/HT.hs +12/−0
- src/Data/Function/HT/Private.hs +16/−3
- src/Data/List/HT.hs +14/−2
- src/Data/List/HT/Private.hs +299/−177
- src/Data/List/Match/Private.hs +75/−11
- src/Data/List/Reverse/Private.hs +50/−0
- src/Data/List/Reverse/StrictElement.hs +19/−1
- src/Data/List/Reverse/StrictSpine.hs +19/−4
- src/Data/Maybe/HT.hs +7/−1
- src/Data/Monoid/HT.hs +34/−2
- src/DocTest/Data/Bool/HT/Private.hs +27/−0
- src/DocTest/Data/Function/HT/Private.hs +33/−0
- src/DocTest/Data/List/HT/Private.hs +658/−0
- src/DocTest/Data/List/Match/Private.hs +143/−0
- src/DocTest/Data/List/Reverse/Private.hs +35/−0
- src/DocTest/Data/List/Reverse/StrictElement.hs +50/−0
- src/DocTest/Data/List/Reverse/StrictSpine.hs +55/−0
- src/DocTest/Data/Maybe/HT.hs +18/−0
- src/DocTest/Data/Monoid/HT.hs +36/−0
- src/Test.hs +21/−20
- src/Test/Data/Function.hs +0/−27
- src/Test/Data/List.hs +0/−208
- src/Test/Data/List/Reverse/StrictElement.hs +0/−53
- src/Test/Data/List/Reverse/StrictSpine.hs +0/−62
- src/Test/Data/ListMatch.hs +0/−77
- src/Test/Data/Maybe.hs +0/−17
- src/Test/Utility.hs +10/−0
- test-module.list +9/−0
- utility-ht.cabal +19/−18
+ Makefile view
@@ -0,0 +1,18 @@+ghci:+ ghci -i:src -Wall src/Data/List/HT.hs++jhc:+ jhc -i src --build-hl utility-ht.jhc-cabal++jhc-test:+ jhc -p utility-ht -i src src/Test.hs+++run-test: update-test+ runhaskell Setup configure --user --enable-tests+ runhaskell Setup build+ runhaskell Setup haddock+ runhaskell Setup test --show-details=streaming++update-test:+ doctest-extract -i src/ -o src/ --module-prefix DocTest --executable-main=Test.hs --import-tested $$(cat test-module.list)
src/Data/Bool/HT/Private.hs view
@@ -51,7 +51,11 @@ {- | Like the @?@ operator of the C progamming language.-Example: @bool ?: ("yes", "no")@.++>>> True ?: ("yes", "no")+"yes"+>>> False ?: ("yes", "no")+"no" -} {-# INLINE (?:) #-} (?:) :: Bool -> (a,a) -> a@@ -64,7 +68,9 @@ {- | Logical operator for implication. -Funnily because of the ordering of 'Bool' it holds @implies == (<=)@.+Funnily because of the ordering of 'Bool' it holds:++prop> \a b -> implies a b == (a<=b) -} {-# INLINE implies #-} implies :: Bool -> Bool -> Bool
src/Data/Either/HT.hs view
@@ -2,6 +2,9 @@ mapLeft, mapRight, mapBoth,+ maybeLeft,+ maybeRight,+ swap, ) where @@ -13,3 +16,12 @@ mapBoth :: (a -> c) -> (b -> d) -> Either a b -> Either c d mapBoth f g = either (Left . f) (Right . g)++maybeLeft :: Either a b -> Maybe a+maybeLeft = either Just (const Nothing)++maybeRight :: Either a b -> Maybe b+maybeRight = either (const Nothing) Just++swap :: Either a b -> Either b a+swap = either Right Left
src/Data/Function/HT/Private.hs view
@@ -4,6 +4,9 @@ import Data.Maybe.HT (toMaybe) import Data.Tuple.HT (swap) +-- $setup+-- >>> import Test.QuickCheck (NonNegative(NonNegative))+ {- | Compositional power of a function, i.e. apply the function @n@ times to a value.@@ -11,10 +14,15 @@ in Simon Thompson: \"The Craft of Functional Programming\", page 172 -} {-# INLINE nest #-}-nest, nest1, nest2 :: Int -> (a -> a) -> a -> a+nest :: Int -> (a -> a) -> a -> a nest 0 _ x = x nest n f x = f (nest (n-1) f x) +{- |+prop> \(NonNegative n) x -> nest n succ x == nest1 n succ (x::Integer)+prop> \(NonNegative n) x -> nest n succ x == nest2 n succ (x::Integer)+-}+nest1, nest2 :: Int -> (a -> a) -> a -> a nest1 n f = foldr (.) id (replicate n f) nest2 n f x = iterate f x !! n @@ -30,13 +38,18 @@ -} {-# INLINE powerAssociative #-}-powerAssociative, powerAssociativeList, powerAssociativeNaive ::- (a -> a -> a) -> a -> a -> Integer -> a+powerAssociative :: (a -> a -> a) -> a -> a -> Integer -> a powerAssociative op = let go acc _ 0 = acc go acc a n = go (if even n then acc else op acc a) (op a a) (div n 2) in go +{- |+prop> \a0 a (NonNegative n) -> powerAssociative (+) a0 a n == (powerAssociativeList (+) a0 a n :: Integer)+prop> \a0 a (NonNegative n) -> powerAssociative (+) a0 a n == (powerAssociativeNaive (+) a0 a n :: Integer)+-}+powerAssociativeList, powerAssociativeNaive ::+ (a -> a -> a) -> a -> a -> Integer -> a powerAssociativeList op a0 a n = foldl (\acc (bit,pow) -> if bit==0 then acc else op acc pow) a0 $ zip
src/Data/List/HT.hs view
@@ -14,8 +14,10 @@ L.takeUntil, L.segmentAfter, L.segmentBefore,- L.segmentAfterMaybe,- L.segmentBeforeMaybe,+ L.segmentAfterJust, segmentAfterMaybe,+ L.segmentBeforeJust, segmentBeforeMaybe,+ L.segmentAfterRight,+ L.segmentBeforeRight, L.removeEach, L.splitEverywhere, -- * inspect ends of a list@@ -36,6 +38,8 @@ L.partitionMaybe, L.takeWhileJust, L.dropWhileNothing,+ L.breakJust,+ L.spanJust, L.unzipEithers, -- * Sieve and slice L.sieve,@@ -77,3 +81,11 @@ {-# DEPRECATED takeWhileRev "Use takeWhile from Data.List.Reverse.StrictElement or Data.List.Reverse.StrictSpine instead" #-} takeWhileRev :: (a -> Bool) -> [a] -> [a] takeWhileRev = Rev.takeWhile++{-# DEPRECATED segmentBeforeMaybe "use segmentBeforeJust instead" #-}+segmentBeforeMaybe :: (a -> Maybe b) -> [a] -> ([a], [(b, [a])])+segmentBeforeMaybe = L.segmentBeforeJust++{-# DEPRECATED segmentAfterMaybe "use segmentAfterJust instead" #-}+segmentAfterMaybe :: (a -> Maybe b) -> [a] -> ([([a], b)], [a])+segmentAfterMaybe = L.segmentAfterJust
src/Data/List/HT/Private.hs view
@@ -18,6 +18,25 @@ import Prelude hiding (unzip, break, span, ) +-- $setup+-- >>> import qualified Test.QuickCheck as QC+-- >>> import Test.Utility (forAllPredicates)+-- >>> import Test.QuickCheck (NonNegative(NonNegative), Positive(Positive), NonEmptyList(NonEmpty))+-- >>> import qualified Data.List as List+-- >>> import Data.List (transpose)+-- >>> import Data.Maybe.HT (toMaybe)+-- >>> import Data.Maybe (mapMaybe, isNothing)+-- >>> import Data.Char (isLetter, toUpper)+-- >>> import Data.Eq.HT (equating)+-- >>> import Control.Monad (liftM2)+-- >>>+-- >>> divMaybe :: Int -> Int -> Maybe Int+-- >>> divMaybe m n = case divMod n m of (q,0) -> Just q; _ -> Nothing+-- >>>+-- >>> forAllMaybeFn :: (QC.Testable test) => ((Int -> Maybe Int) -> test) -> QC.Property+-- >>> forAllMaybeFn prop = QC.forAll (QC.choose (1,4)) $ prop . divMaybe++ -- * Improved standard functions {- |@@ -79,13 +98,15 @@ If two adjacent elements satisfy a relation then they are put into the same sublist. Example: -> groupBy (<) "abcdebcdef" == ["abcde","bcdef"]+>>> groupBy (<) "abcdebcdef"+["abcde","bcdef"] In contrast to that 'Data.List.groupBy' compares the head of each sublist with each candidate for this sublist. This yields -> List.groupBy (<) "abcdebcdef" == ["abcdebcdef"]+>>> List.groupBy (<) "abcdebcdef"+["abcdebcdef"] The second @'b'@ is compared with the leading @'a'@. Thus it is put into the same sublist as @'a'@.@@ -155,21 +176,20 @@ This is somehow a generalization of 'lines' and 'words'. But note the differences: -> Prelude Data.List.HT> words "a a"-> ["a","a"]-> Prelude Data.List.HT> chop (' '==) "a a"-> ["a","","a"]--> Prelude Data.List.HT> lines "a\n\na"-> ["a","","a"]-> Prelude Data.List.HT> chop ('\n'==) "a\n\na"-> ["a","","a"]+>>> words "a a"+["a","a"]+>>> chop (' '==) "a a"+["a","","a"] -> Prelude Data.List.HT> lines "a\n"-> ["a"]-> Prelude Data.List.HT> chop ('\n'==) "a\n"-> ["a",""]+>>> lines "a\n\na"+["a","","a"]+>>> chop ('\n'==) "a\n\na"+["a","","a"] +>>> lines "a\n"+["a"]+>>> chop ('\n'==) "a\n"+["a",""] -} chop :: (a -> Bool) -> [a] -> [[a]] chop p =@@ -196,6 +216,8 @@ {- | Like 'break', but splits after the matching element.++prop> forAllPredicates $ \p xs -> uncurry (++) (breakAfter p xs) == xs -} breakAfter :: (a -> Bool) -> [a] -> ([a], [a]) breakAfter = breakAfterRec@@ -214,6 +236,7 @@ The use of 'foldr' might allow for fusion, but unfortunately this simple implementation would copy the tail of the list. -}+-- | prop> forAllPredicates $ \p xs -> breakAfterRec p xs == breakAfterFoldr p xs breakAfterFoldr :: (a -> Bool) -> [a] -> ([a], [a]) breakAfterFoldr p = forcePair .@@ -221,12 +244,14 @@ (\x yzs -> mapFst (x:) $ if p x then ([], uncurry (++) yzs) else yzs) ([],[]) +-- | prop> forAllPredicates $ \p xs -> breakAfterRec p xs == breakAfterBreak p xs breakAfterBreak :: (a -> Bool) -> [a] -> ([a], [a]) breakAfterBreak p xs = case break p xs of (ys, []) -> (ys, []) (ys, z:zs) -> (ys++[z], zs) +-- | prop> forAllPredicates $ \p xs -> breakAfterRec p xs == breakAfterTakeUntil p xs breakAfterTakeUntil :: (a -> Bool) -> [a] -> ([a], [a]) breakAfterTakeUntil p xs = forcePair $@@ -237,7 +262,9 @@ Take all elements until one matches. The matching element is returned, too. This is the key difference to @takeWhile (not . p)@.-It holds @takeUntil p xs == fst (breakAfter p xs)@.+It holds:++prop> forAllPredicates $ \p xs -> takeUntil p xs == fst (breakAfter p xs) -} takeUntil :: (a -> Bool) -> [a] -> [a] takeUntil p = foldr (\x ys -> x : if p x then [] else ys) []@@ -249,6 +276,15 @@ There is always a list for the part after the last terminator. It may be empty. See package @non-empty@ for more precise result type.++prop> forAllPredicates $ \p xs -> concat (segmentAfter p xs) == xs+prop> forAllPredicates $ \p xs -> length (filter p xs) == length (tail (segmentAfter p xs))+prop> forAllPredicates $ \p -> all (p . last) . init . segmentAfter p+prop> forAllPredicates $ \p -> all (all (not . p) . init) . init . segmentAfter p++This test captures both infinitely many groups and infinitely big groups:++prop> forAllPredicates $ \p x -> flip seq True . (!!100) . concat . segmentAfter p . cycle . (x:) -} segmentAfter :: (a -> Bool) -> [a] -> [[a]] segmentAfter p =@@ -263,35 +299,18 @@ segmentAfter' p = foldr (\ x ~yt@(y:ys) -> if p x then [x]:yt else (x:y):ys) [[]] -propSegmentAfterConcat :: Eq a => (a -> Bool) -> [a] -> Bool-propSegmentAfterConcat p xs =- concat (segmentAfter p xs) == xs--propSegmentAfterNumSeps :: (a -> Bool) -> [a] -> Bool-propSegmentAfterNumSeps p xs =- length (filter p xs) == length (tail (segmentAfter p xs))--propSegmentAfterLasts :: (a -> Bool) -> [a] -> Bool-propSegmentAfterLasts p =- all (p . last) . init . segmentAfter p--propSegmentAfterInits :: (a -> Bool) -> [a] -> Bool-propSegmentAfterInits p =- all (all (not . p) . init) . init . segmentAfter p--{--This test captures both infinitely many groups and infinitely big groups.--}-propSegmentAfterInfinite :: (a -> Bool) -> a -> [a] -> Bool-propSegmentAfterInfinite p x =- flip seq True . (!!100) . concat . segmentAfter p . cycle . (x:)- {- | Split the list before each occurence of a leading character. Keep these characters. There is always a list for the part before the first leading character. It may be empty. See package @non-empty@ for more precise result type.++prop> forAllPredicates $ \p xs -> concat (segmentBefore p xs) == xs+prop> forAllPredicates $ \p xs -> length (filter p xs) == length (tail (segmentBefore p xs))+prop> forAllPredicates $ \p -> all (p . head) . tail . segmentBefore p+prop> forAllPredicates $ \p -> all (all (not . p) . tail) . tail . segmentBefore p+prop> forAllPredicates $ \p x -> flip seq True . (!!100) . concat . segmentBefore p . cycle . (x:) -} segmentBefore :: (a -> Bool) -> [a] -> [[a]] segmentBefore p =@@ -303,6 +322,7 @@ in if p x then ([],xs:ys) else (xs,ys)) ([],[]) +-- | prop> forAllPredicates $ \p xs -> segmentBefore p xs == segmentBefore' p xs segmentBefore' :: (a -> Bool) -> [a] -> [[a]] segmentBefore' p = uncurry (:) .@@ -313,6 +333,7 @@ return (x:xs, xss)) . groupBy (\_ x -> not $ p x) +-- | prop> forAllPredicates $ \p xs -> segmentBefore p xs == segmentBefore'' p xs segmentBefore'' :: (a -> Bool) -> [a] -> [[a]] segmentBefore'' p = (\xst ->@@ -323,43 +344,14 @@ (error "segmentBefore: dummy element" :) -propSegmentBeforeConcat :: Eq a => (a -> Bool) -> [a] -> Bool-propSegmentBeforeConcat p xs =- concat (segmentBefore p xs) == xs--propSegmentBeforeNumSeps :: (a -> Bool) -> [a] -> Bool-propSegmentBeforeNumSeps p xs =- length (filter p xs) == length (tail (segmentBefore p xs))--propSegmentBeforeHeads :: (a -> Bool) -> [a] -> Bool-propSegmentBeforeHeads p =- all (p . head) . tail . segmentBefore p--propSegmentBeforeTails :: (a -> Bool) -> [a] -> Bool-propSegmentBeforeTails p =- all (all (not . p) . tail) . tail . segmentBefore p--propSegmentBeforeInfinite :: (a -> Bool) -> a -> [a] -> Bool-propSegmentBeforeInfinite p x =- flip seq True . (!!100) . concat . segmentBefore p . cycle . (x:)--propSegmentBeforeGroupBy0 :: Eq a => (a -> Bool) -> [a] -> Bool-propSegmentBeforeGroupBy0 p xs =- segmentBefore p xs == segmentBefore' p xs--propSegmentBeforeGroupBy1 :: Eq a => (a -> Bool) -> [a] -> Bool-propSegmentBeforeGroupBy1 p xs =- segmentBefore p xs == segmentBefore'' p xs-- {- |-> Data.List.HT Data.Char> segmentBeforeMaybe (\c -> toMaybe (isLetter c) (toUpper c)) "123a5345b---"-> ("123",[('A',"5345"),('B',"---")])+>>> segmentBeforeJust (\c -> toMaybe (isLetter c) (toUpper c)) "123a5345b---"+("123",[('A',"5345"),('B',"---")]) -}-segmentBeforeMaybe ::+segmentBeforeJust :: (a -> Maybe b) -> [a] -> ([a], [(b, [a])])-segmentBeforeMaybe f =+segmentBeforeJust f = forcePair . foldr (\ x ~(y,ys) ->@@ -369,18 +361,49 @@ ([],[]) {- |-> Data.List.HT Data.Char> segmentAfterMaybe (\c -> toMaybe (isLetter c) (toUpper c)) "123a5345b---"-> ([("123",'A'),("5345",'B')],"---")+>>> segmentAfterJust (\c -> toMaybe (isLetter c) (toUpper c)) "123a5345b---"+([("123",'A'),("5345",'B')],"---") -}-segmentAfterMaybe ::+segmentAfterJust :: (a -> Maybe b) -> [a] -> ([([a], b)], [a])-segmentAfterMaybe f =+segmentAfterJust f = swap . uncurry (mapAccumL (\as0 (b,as1) -> (as1, (as0,b)))) .- segmentBeforeMaybe f+ segmentBeforeJust f +{- |+>>> segmentBeforeRight [Left 'a', Right LT, Right GT, Left 'b']+("a",[(LT,""),(GT,"b")])++prop> forAllMaybeFn $ \f xs -> segmentBeforeJust f xs == segmentBeforeRight (map (\x -> maybe (Left x) Right (f x)) xs)+-}+segmentBeforeRight ::+ [Either a b] -> ([a], [(b, [a])])+segmentBeforeRight =+ forcePair .+ foldr+ (\ x ~(y,ys) ->+ case x of+ Right b -> ([],(b,y):ys)+ Left a -> (a:y,ys))+ ([],[])++{- |+>>> segmentAfterRight [Left 'a', Right LT, Right GT, Left 'b']+([("a",LT),("",GT)],"b")++prop> forAllMaybeFn $ \f xs -> segmentAfterJust f xs == segmentAfterRight (map (\x -> maybe (Left x) Right (f x)) xs)+-}+segmentAfterRight ::+ [Either a b] -> ([([a], b)], [a])+segmentAfterRight =+ swap .+ uncurry (mapAccumL (\as0 (b,as1) -> (as1, (as0,b)))) .+ segmentBeforeRight++ -- cf. Matroid.hs {- | @removeEach xs@ represents a list of sublists of @xs@,@@ -393,11 +416,26 @@ See also the proposal <http://www.haskell.org/pipermail/libraries/2008-February/009270.html>++>>> removeEach "abc"+[('a',"bc"),('b',"ac"),('c',"ab")]+>>> removeEach "a"+[('a',"")]+>>> removeEach ""+[] -} removeEach :: [a] -> [(a, [a])] removeEach = map (\(ys, pivot, zs) -> (pivot,ys++zs)) . splitEverywhere +{- |+>>> splitEverywhere "abc"+[("",'a',"bc"),("a",'b',"c"),("ab",'c',"")]+>>> splitEverywhere "a"+[("",'a',"")]+>>> splitEverywhere ""+[]+-} splitEverywhere :: [a] -> [([a], a, [a])] splitEverywhere xs = map@@ -417,6 +455,8 @@ but 'splitLast' is more efficient if the last element is accessed after the initial ones, because it avoids memoizing list.++prop> \(NonEmpty xs) -> splitLast (xs::String) == (init xs, last xs) -} splitLast :: [a] -> ([a], a) splitLast [] = error "splitLast: empty list"@@ -424,11 +464,7 @@ splitLast (x:xs) = let (xs', lastx) = splitLast xs in (x:xs', lastx) -propSplitLast :: Eq a => [a] -> Bool-propSplitLast xs =- splitLast xs == (init xs, last xs) - {- | Should be prefered to 'head' and 'tail'. -}@@ -439,17 +475,13 @@ {- | Should be prefered to 'init' and 'last'.++prop> \xs -> maybe True ((init xs, last xs) == ) (viewR (xs::String)) -} viewR :: [a] -> Maybe ([a], a) viewR = foldr (\x -> Just . forcePair . maybe ([],x) (mapFst (x:))) Nothing -propViewR :: Eq a => [a] -> Bool-propViewR xs =- maybe True- ((init xs, last xs) == )- (viewR xs)- {- | Should be prefered to 'head' and 'tail'. -}@@ -464,23 +496,22 @@ {- | Should be prefered to 'init' and 'last'.++prop> \xs -> switchR True (\ixs lxs -> ixs == init xs && lxs == last xs) (xs::String) -} {-# INLINE switchR #-} switchR :: b -> ([a] -> a -> b) -> [a] -> b switchR n j = maybe n (uncurry j) . viewR -propSwitchR :: Eq a => [a] -> Bool-propSwitchR xs =- switchR True (\ixs lxs -> ixs == init xs && lxs == last xs) xs -- -- * List processing starting at the end {- | @takeRev n@ is like @reverse . take n . reverse@ but it is lazy enough to work for infinite lists, too.++prop> \n xs -> takeRev n (xs::String) == reverse (take n (reverse xs)) -} takeRev :: Int -> [a] -> [a] takeRev n xs = Match.drop (drop n xs) xs@@ -488,46 +519,22 @@ {- | @dropRev n@ is like @reverse . drop n . reverse@ but it is lazy enough to work for infinite lists, too.++prop> \n xs -> dropRev n (xs::String) == reverse (drop n (reverse xs)) -} dropRev :: Int -> [a] -> [a] dropRev n xs = Match.take (drop n xs) xs {- | @splitAtRev n xs == (dropRev n xs, takeRev n xs)@.-It holds @xs == uncurry (++) (splitAtRev n xs)@++prop> \n xs -> splitAtRev n (xs::String) == (dropRev n xs, takeRev n xs)+prop> \n xs -> (xs::String) == uncurry (++) (splitAtRev n xs) -} splitAtRev :: Int -> [a] -> ([a], [a]) splitAtRev n xs = Match.splitAt (drop n xs) xs -dropWhileRev :: (a -> Bool) -> [a] -> [a]-dropWhileRev p =- concat . init . segmentAfter (not . p)--takeWhileRev0 :: (a -> Bool) -> [a] -> [a]-takeWhileRev0 p =- last . segmentAfter (not . p)--{- |-Doesn't seem to be superior to the naive implementation.--}-takeWhileRev1 :: (a -> Bool) -> [a] -> [a]-takeWhileRev1 p =- (\mx ->- case mx of- Just (_, xs@((True,_):_)) -> map snd xs- _ -> []) .- viewR . Key.aux groupBy (==) p--{- |-However it is more inefficient,-because of repeatedly appending single elements. :-(--}-takeWhileRev2 :: (a -> Bool) -> [a] -> [a]-takeWhileRev2 p =- foldl (\xs x -> if p x then xs++[x] else []) []-- -- * List processing with Maybe and Either {- |@@ -535,12 +542,23 @@ where @zs@ is @ys@ without the prefix @xs@. Otherwise it is @Nothing@. It is the same as 'Data.List.stripPrefix'.++>>> maybePrefixOf "abc" "abcdef"+Just "def"+>>> maybePrefixOf "def" "abcdef"+Nothing -} maybePrefixOf :: Eq a => [a] -> [a] -> Maybe [a] maybePrefixOf (x:xs) (y:ys) = guard (x==y) >> maybePrefixOf xs ys maybePrefixOf [] ys = Just ys maybePrefixOf _ [] = Nothing +{- |+>>> maybeSuffixOf "abc" "abcdef"+Nothing+>>> maybeSuffixOf "def" "abcdef"+Just "abc"+-} maybeSuffixOf :: Eq a => [a] -> [a] -> Maybe [a] maybeSuffixOf xs ys = fmap reverse $ maybePrefixOf (reverse xs) (reverse ys)@@ -549,8 +567,8 @@ {- | Partition a list into elements which evaluate to @Just@ or @Nothing@ by @f@. -It holds @mapMaybe f == fst . partitionMaybe f@-and @partition p == partitionMaybe (\ x -> toMaybe (p x) x)@.+prop> forAllMaybeFn $ \f xs -> partitionMaybe f xs == (mapMaybe f xs, filter (isNothing . f) xs)+prop> forAllPredicates $ \p xs -> partition p xs == partitionMaybe (\x -> toMaybe (p x) x) xs -} partitionMaybe :: (a -> Maybe b) -> [a] -> ([b], [a]) partitionMaybe f =@@ -563,10 +581,13 @@ This is the cousin of 'takeWhile' analogously to 'catMaybes' being the cousin of 'filter'. -Example: Keep the heads of sublists until an empty list occurs.+>>> takeWhileJust [Just 'a', Just 'b', Nothing, Just 'c']+"ab" -> takeWhileJust $ map (fmap fst . viewL) xs+Example: Keep the heads of sublists until an empty list occurs. +>>> takeWhileJust $ map (fmap fst . viewL) ["abc","def","","xyz"]+"ad" For consistency with 'takeWhile', 'partitionMaybe' and 'dropWhileNothing' it should have been:@@ -586,12 +607,14 @@ dropWhileNothing f = msum . map (Func.mapFst f <=< viewL) . tails +-- | prop> forAllMaybeFn $ \f xs -> dropWhileNothing f xs == dropWhileNothingRec f xs dropWhileNothingRec :: (a -> Maybe b) -> [a] -> Maybe (b, [a]) dropWhileNothingRec f = let go [] = Nothing go (a:xs) = (flip (,) xs <$> f a) `mplus` go xs in go +-- | prop> forAllMaybeFn $ \f xs -> snd (breakJust f xs) == dropWhileNothing f xs breakJust :: (a -> Maybe b) -> [a] -> ([a], Maybe (b, [a])) breakJust f = let go [] = ([], Nothing)@@ -602,6 +625,7 @@ in go -- memory leak, because xs is hold all the time+-- | prop> forAllMaybeFn $ \f xs -> breakJust f xs == breakJustRemoveEach f xs breakJustRemoveEach :: (a -> Maybe b) -> [a] -> ([a], Maybe (b, [a])) breakJustRemoveEach f xs = switchL (xs, Nothing) const $@@ -609,6 +633,7 @@ splitEverywhere xs -- needs to apply 'f' twice at the end and uses partial functions+-- | prop> forAllMaybeFn $ \f xs -> breakJust f xs == breakJustPartial f xs breakJustPartial :: (a -> Maybe b) -> [a] -> ([a], Maybe (b, [a])) breakJustPartial f xs = let (ys,zs) = break (isJust . f) xs@@ -616,7 +641,16 @@ mapFst (maybe (error "breakJust: unexpected Nothing") id . f) <$> viewL zs) +spanJust :: (a -> Maybe b) -> [a] -> ([b], [a])+spanJust f =+ let go [] = ([], [])+ go xt@(a:xs) =+ case f a of+ Just b -> mapFst (b:) $ go xs+ Nothing -> ([], xt)+ in go + unzipEithers :: [Either a b] -> ([a], [b]) unzipEithers = forcePair .@@ -625,73 +659,84 @@ -- * Sieve and slice -{-| keep every k-th value from the list -}+{- | keep every k-th value from the list++>>> sieve 6 ['a'..'z']+"agmsy"+-} sieve, sieve', sieve'', sieve''' :: Int -> [a] -> [a] sieve k = unfoldr (\xs -> toMaybe (not (null xs)) (head xs, drop k xs)) +-- | prop> \(Positive n) xs -> sieve n xs == sieve' n (xs::String) sieve' k = map head . sliceVertical k +-- | prop> \(Positive n) xs -> sieve n xs == sieve'' n (xs::String) sieve'' k x = map (x!!) [0,k..(length x-1)] +-- | prop> \(Positive n) xs -> sieve n xs == sieve''' n (xs::String) sieve''' k = map head . takeWhile (not . null) . iterate (drop k) -propSieve :: Eq a => Int -> [a] -> Bool-propSieve n x =- sieve n x == sieve' n x &&- sieve n x == sieve'' n x {- sliceHorizontal is faster than sliceHorizontal' but consumes slightly more memory (although it needs no swapping) -}+{- |+>>> sliceHorizontal 6 ['a'..'z']+["agmsy","bhntz","ciou","djpv","ekqw","flrx"]++prop> \(NonEmpty xs) -> QC.forAll (QC.choose (1, length xs)) $ \n -> sliceHorizontal n xs == transpose (sliceVertical n (xs::String))+prop> \(NonEmpty xs) -> QC.forAll (QC.choose (1, length xs)) $ \n -> sliceVertical n xs == transpose (sliceHorizontal n (xs::String))++The properties do not hold for empty lists because of:++>>> sliceHorizontal 4 ([]::[Int])+[[],[],[],[]]+-} sliceHorizontal, sliceHorizontal', sliceHorizontal'', sliceHorizontal''' :: Int -> [a] -> [[a]] sliceHorizontal n = map (sieve n) . take n . iterate (drop 1) +-- | prop> \(NonNegative n) xs -> sliceHorizontal n xs == sliceHorizontal' n (xs::String) sliceHorizontal' n = foldr (\x ys -> let y = last ys in Match.take ys ((x:y):ys)) (replicate n []) +-- | prop> \(Positive n) xs -> sliceHorizontal n xs == sliceHorizontal'' n (xs::String) sliceHorizontal'' n = reverse . foldr (\x ~(y:ys) -> ys ++ [x:y]) (replicate n []) sliceHorizontal''' n = take n . transpose . takeWhile (not . null) . iterate (drop n) -propSliceHorizontal :: Eq a => Int -> [a] -> Bool-propSliceHorizontal n x =- sliceHorizontal n x == sliceHorizontal' n x &&- sliceHorizontal n x == sliceHorizontal'' n x &&- sliceHorizontal n x == sliceHorizontal''' n x -+{- |+>>> sliceVertical 6 ['a'..'z']+["abcdef","ghijkl","mnopqr","stuvwx","yz"]+-} sliceVertical, sliceVertical' :: Int -> [a] -> [[a]] sliceVertical n = map (take n) . takeWhile (not . null) . iterate (drop n) {- takeWhile must be performed before (map take) in order to handle (n==0) correctly -} +-- | prop> \(NonNegative n) xs -> equating (take 100000) (sliceVertical n xs) (sliceVertical' n (xs::String)) sliceVertical' n = unfoldr (\x -> toMaybe (not (null x)) (splitAt n x)) -propSliceVertical :: Eq a => Int -> [a] -> Bool-propSliceVertical n x =- take 100000 (sliceVertical n x) == take 100000 (sliceVertical' n x) -propSlice :: Eq a => Int -> [a] -> Bool-propSlice n x =- -- problems: sliceHorizontal 4 [] == [[],[],[],[]]- sliceHorizontal n x == transpose (sliceVertical n x) &&- sliceVertical n x == transpose (sliceHorizontal n x) - -- * Search&replace search :: (Eq a) => [a] -> [a] -> [Int] search sub str = findIndices (isPrefixOf sub) (tails str) +{- |+prop> \(NonEmpty xs) ys -> replace xs xs ys == (ys::String)+prop> \(NonEmpty xs) (NonEmpty ys) -> equating (take 1000) (replace xs ys (cycle xs)) (cycle (ys::String))+-} replace :: Eq a => [a] -> [a] -> [a] -> [a] replace src dst = let recourse [] = []@@ -716,14 +761,6 @@ replace' src dst xs = concatMap (fromMaybe dst) (markSublists src xs) -propReplaceId :: (Eq a) => [a] -> [a] -> Bool-propReplaceId xs ys =- replace xs xs ys == ys--propReplaceCycle :: (Eq a) => [a] -> [a] -> Bool-propReplaceCycle xs ys =- replace xs ys (cycle xs) == cycle ys- {- | This is slightly wrong, because it re-replaces things. That's also the reason for inefficiency: The replacing can go on only when subsequent replacements are finished.@@ -735,6 +772,9 @@ then dst ++ drop (length src) y else y) [] +{- |+prop \src dst xs -> replace src dst xs == multiReplace [(src,dst)] (xs::String)+-} multiReplace :: Eq a => [([a], [a])] -> [a] -> [a] multiReplace dict = let recourse [] = []@@ -757,11 +797,7 @@ (find (flip isPrefixOf str . fst) dict) in recourse -propMultiReplaceSingle :: Eq a => [a] -> [a] -> [a] -> Bool-propMultiReplaceSingle src dst x =- replace src dst x == multiReplace [(src,dst)] x - -- * Lists of lists {- |@@ -836,6 +872,8 @@ It's like 'shear' but the order of elements in the sub list is reversed. Its implementation seems to be more efficient than that of 'shear'. If the order does not matter, better choose 'shearTranspose'.++prop> \xs -> shearTranspose xs == map reverse (shear (xs::[String])) -} shearTranspose :: [[a]] -> [[a]] shearTranspose =@@ -868,9 +906,9 @@ {- | Operate on each combination of elements of the first and the second list. In contrast to the list instance of 'Monad.liftM2'-in holds the results in a list of lists.-It holds-@concat (outerProduct f xs ys) == liftM2 f xs ys@+it holds the results in a list of lists.++prop> \xs ys -> let f x y = (x::Char,y::Int) in concat (outerProduct f xs ys) == liftM2 f xs ys -} outerProduct :: (a -> b -> c) -> [a] -> [b] -> [[c]] outerProduct f xs ys = map (flip map ys . f) xs@@ -892,15 +930,14 @@ then x : takeWhileMulti aps xs else takeWhileMulti ps axs +{- |+prop> \ys xs -> let ps = map (<=) ys in takeWhileMulti ps xs == takeWhileMulti' ps (xs::String)+-} takeWhileMulti' :: [a -> Bool] -> [a] -> [a] takeWhileMulti' ps xs = concatMap fst (tail (scanl (flip span . snd) (undefined,xs) ps)) -propTakeWhileMulti :: (Eq a) => [a -> Bool] -> [a] -> Bool-propTakeWhileMulti ps xs =- takeWhileMulti ps xs == takeWhileMulti' ps xs- {- Debug.QuickCheck.quickCheck (propTakeWhileMulti [(<0), (>0), odd, even, ((0::Int)==)]) -}@@ -947,18 +984,51 @@ -} +{- |+>>> lengthAtLeast 0 ""+True+>>> lengthAtLeast 3 "ab"+False+>>> lengthAtLeast 3 "abc"+True+>>> lengthAtLeast 3 $ repeat 'a'+True+>>> lengthAtLeast 3 $ "abc" ++ undefined+True++prop> \n xs -> lengthAtLeast n (xs::String) == (length xs >= n)+-} lengthAtLeast :: Int -> [a] -> Bool lengthAtLeast n = if n<=0 then const True else not . null . drop (n-1) +{- |+>>> lengthAtMost 0 ""+True+>>> lengthAtMost 3 "ab"+True+>>> lengthAtMost 3 "abc"+True+>>> lengthAtMost 3 "abcd"+False+>>> lengthAtMost 3 $ repeat 'a'+False+>>> lengthAtMost 3 $ "abcd" ++ undefined+False++prop> \n xs -> lengthAtMost n (xs::String) == (length xs <= n)+-} lengthAtMost :: Int -> [a] -> Bool lengthAtMost n = if n<0 then const False else null . drop n +{- |+prop> \n xs -> lengthAtMost0 n (xs::String) == (length xs <= n)+-} lengthAtMost0 :: Int -> [a] -> Bool lengthAtMost0 n = (n>=) . length . take (n+1) @@ -1002,34 +1072,61 @@ rotate n x = Match.take x (drop (mod n (length x)) (cycle x)) -{- | more efficient implementation of rotate' -}+{- | more efficient implementation of rotate'++prop> \(NonNegative n) (NonEmpty xs) -> rotate n xs == rotate' n (xs::String)+-} rotate' n x = uncurry (flip (++)) (splitAt (mod n (length x)) x) +{- |+prop> \(NonNegative n) xs -> rotate n xs == rotate'' n (xs::String)+-} rotate'' n x = Match.take x (drop n (cycle x)) -propRotate :: Eq a => Int -> [a] -> Bool-propRotate n x =- rotate n x == rotate' n x &&- rotate n x == rotate'' n x-{- Debug.QuickCheck.quickCheck- (\n x -> n>=0 Debug.QuickCheck.==>- List.HT.propRotate n ((0::Int):x)) -}--{-|+{- | Given two lists that are ordered (i.e. @p x y@ holds for subsequent @x@ and @y@) 'mergeBy' them into a list that is ordered, again.++>>> mergeBy (<=) "agh" "begz"+"abegghz" -} mergeBy :: (a -> a -> Bool) -> [a] -> [a] -> [a] mergeBy = Key.mergeBy +{- |+>>> allEqual "aab"+False+>>> allEqual "aaa"+True+>>> allEqual "aa"+True+>>> allEqual "a"+True+>>> allEqual ""+True+-} allEqual :: Eq a => [a] -> Bool allEqual = and . mapAdjacent (==) +{- |+>>> isAscending "abc"+True+>>> isAscending "abb"+True+>>> isAscending "aba"+False+>>> isAscending "cba"+False+>>> isAscending "a"+True+>>> isAscending ""+True+-} isAscending :: (Ord a) => [a] -> Bool isAscending = and . isAscendingLazy @@ -1039,21 +1136,33 @@ {- | This function combines every pair of neighbour elements in a list with a certain function.++>>> mapAdjacent (<=) ""+[]+>>> mapAdjacent (<=) "a"+[]+>>> mapAdjacent (<=) "aba"+[True,False]+>>> mapAdjacent (,) "abc"+[('a','b'),('b','c')]++prop> \x xs -> mapAdjacent subtract (scanl (+) x xs) == (xs::[Integer]) -} mapAdjacent :: (a -> a -> b) -> [a] -> [b] mapAdjacent f xs = zipWith f xs (tail xs) {- | <http://mail.haskell.org/libraries/2016-April/026912.html>++prop> \xs -> mapAdjacent (,) xs == mapAdjacentPointfree (,) (xs::String) -} mapAdjacentPointfree :: (a -> a -> b) -> [a] -> [b] mapAdjacentPointfree f = zipWith f <*> tail {- |-> mapAdjacent f a0 [(a1,b1), (a2,b2), (a3,b3)]-> ==-> [f a0 a1 b1, f a1 a2 b2, f a2 a3 b3]+>>> let f x y z = [x,y]++show(z::Int) in mapAdjacent1 f 'a' [('b',1), ('c',2), ('d',3)]+["ab1","bc2","cd3"] -} mapAdjacent1 :: (a -> a -> b -> c) -> a -> [(a,b)] -> [c] mapAdjacent1 f a xs =@@ -1063,6 +1172,15 @@ {- | Enumerate without Enum context. For Enum equivalent to enumFrom.++>>> range 0 :: [Integer]+[]+>>> range 1 :: [Integer]+[0]+>>> range 8 :: [Integer]+[0,1,2,3,4,5,6,7]++prop> \(NonNegative n) -> length (range n :: [Integer]) == n -} range :: Num a => Int -> [a] range n = take n (iterate (+1) 0)@@ -1088,6 +1206,8 @@ From the list @map (powerAssociative op a a) [0,(2*n)..]@ we compute the list @map (powerAssociative op a a) [0,n..]@, and iterate that until @n==1@.++prop> \x -> equating (take 1000) (List.iterate (x+) x) (iterateAssociative (+) (x::Integer)) -} iterateAssociative :: (a -> a -> a) -> a -> [a] iterateAssociative op a =@@ -1105,6 +1225,8 @@ However it has a space leak, because for the value with index @n@ all elements starting at @div n 2@ must be kept.++prop> \x -> equating (take 1000) (List.iterate (x+) x) (iterateLeaky (+) (x::Integer)) -} iterateLeaky :: (a -> a -> a) -> a -> [a] iterateLeaky op x =
src/Data/List/Match/Private.hs view
@@ -12,7 +12,27 @@ import Prelude hiding (take, drop, splitAt, replicate, ) -{- | Make a list as long as another one -}+-- $setup+-- >>> import qualified Data.List.Match.Private as Match+-- >>> import qualified Data.List as List+-- >>>+-- >>> import qualified Test.QuickCheck as QC+-- >>>+-- >>> newtype List = List [Integer] deriving (Show)+-- >>> instance QC.Arbitrary List where+-- >>> arbitrary = fmap List QC.arbitrary+-- >>> shrink (List xs) = map List $ QC.shrink xs+-- >>>+-- >>> newtype Shape = Shape [Ordering] deriving (Show)+-- >>> instance QC.Arbitrary Shape where+-- >>> arbitrary = fmap Shape QC.arbitrary+-- >>> shrink (Shape xs) = map Shape $ QC.shrink xs+++{- | Make a list as long as another one++prop> \(Shape xs) (List ys) -> Match.take xs ys == List.take (length xs) ys+-} {- @flip (zipWith const)@ is not as lazy, e.g. would be @take [] undefined = undefined@,@@ -21,11 +41,17 @@ take :: [b] -> [a] -> [a] take = zipWith (flip const) -{- | Drop as many elements as the first list is long -}+{- | Drop as many elements as the first list is long++prop> \(Shape xs) (List ys) -> Match.drop xs ys == List.drop (length xs) ys+prop> \(Shape xs) (List ys) -> Match.take xs ys ++ Match.drop xs ys == ys+-} drop :: [b] -> [a] -> [a] drop xs ys0 = foldl (\ys _ -> laxTail ys) ys0 xs ++-- | prop> \(Shape xs) (List ys) -> Match.drop xs ys == dropRec xs ys {- Shares suffix with input, that is it is more efficient than the implementations below.@@ -34,16 +60,19 @@ dropRec (_:xs) (_:ys) = dropRec xs ys dropRec _ ys = ys +-- | prop> \(Shape xs) (List ys) -> Match.drop xs ys == drop0 xs ys drop0 :: [b] -> [a] -> [a] drop0 xs ys = -- catMaybes ( map fromJust (dropWhile isNothing (zipWith (toMaybe . null) (iterate laxTail xs) ys)) +-- | prop> \(Shape xs) (List ys) -> Match.drop xs ys == drop1 xs ys drop1 :: [b] -> [a] -> [a] drop1 xs ys = map snd (dropWhile (not . null . fst) (zip (iterate laxTail xs) ys)) +-- | prop> \(Shape xs) (List ys) -> Match.drop xs ys == drop2 xs ys drop2 :: [b] -> [a] -> [a] drop2 xs ys = snd $ head $@@ -52,14 +81,24 @@ {- |-@laxTail [] = []@+>>> laxTail ""+""+>>> laxTail "a"+""+>>> laxTail "ab"+"b" -} laxTail :: [a] -> [a] laxTail xt = case xt of [] -> []; _:xs -> xs +-- | prop> \(List xs) -> Match.laxTail xs == Match.laxTail0 xs laxTail0 :: [a] -> [a] laxTail0 = List.drop 1 +{- |+prop> \(Shape xs) (List ys) -> Match.splitAt xs ys == (Match.take xs ys, Match.drop xs ys)+prop> \(Shape xs) (List ys) -> Match.splitAt xs ys == List.splitAt (length xs) ys+-} splitAt :: [b] -> [a] -> ([a],[a]) splitAt nt xt = forcePair $@@ -68,15 +107,21 @@ (_, xs) -> ([],xs) +-- | prop> \(Shape xs) (List ys) -> Match.takeRev xs ys == reverse (Match.take xs (reverse ys)) takeRev :: [b] -> [a] -> [a] takeRev ys xs = drop (drop ys xs) xs +-- | prop> \(Shape xs) (List ys) -> Match.dropRev xs ys == reverse (Match.drop xs (reverse ys)) dropRev :: [b] -> [a] -> [a] dropRev ys xs = take (drop ys xs) xs {- | Check whether two lists with different element types have equal length.-It is equivalent to @length xs == length ys@ but more efficient.+It holds++prop> \(Shape xs) (List ys) -> equalLength xs ys == (length xs == length ys)++but 'equalLength' is more efficient. -} equalLength :: [a] -> [b] -> Bool equalLength xs ys =@@ -84,14 +129,20 @@ {- | Compare the length of two lists over different types.-It is equivalent to @(compare (length xs) (length ys))@-but more efficient.+It holds++prop> \(Shape xs) (List ys) -> compareLength xs ys == compare (length xs) (length ys)++but 'compareLength' is more efficient. -} compareLength :: [a] -> [b] -> Ordering compareLength xs ys = compare (void xs) (void ys) -{- | this one uses explicit recursion -}+{- | this one uses explicit recursion++prop> \(Shape xs) (List ys) -> Match.compareLength xs ys == Match.compareLength0 xs ys+-} compareLength0 :: [a] -> [b] -> Ordering compareLength0 = let recourse (_:xs) (_:ys) = recourse xs ys@@ -100,14 +151,21 @@ recourse [] (_:_) = LT in recourse -{- | strict comparison -}+{- | strict comparison++prop> \(Shape xs) (List ys) -> Match.compareLength xs ys == Match.compareLength1 xs ys+-} compareLength1 :: [a] -> [b] -> Ordering compareLength1 xs ys = compare (length xs) (length ys) {- | @lessOrEqualLength x y@ is almost the same as @compareLength x y <= EQ@,-but @lessOrEqualLength [] undefined = True@,+but++>>> lessOrEqualLength "" undefined+True+ whereas @compareLength [] undefined <= EQ = undefined@. -} lessOrEqualLength :: [a] -> [b] -> Bool@@ -118,8 +176,11 @@ {- | Returns the shorter one of two lists. It works also for infinite lists as much as possible.-E.g. @shorterList (shorterList (repeat 1) (repeat 2)) [1,2,3]@-can be computed.+E.g.++>>> shorterList (shorterList (repeat 'a') (repeat 'b')) "abc"+"abc"+ The trick is, that the skeleton of the resulting list is constructed using 'zipWith' without touching the elements. The contents is then computed (only) if requested.@@ -135,6 +196,9 @@ even if it is undefined, which list is the shorter one. However, it requires a proper 'Eq' instance and if elements are undefined, it may fail even earlier.++>>> List.take 3 $ shorterListEq ("abc" ++ repeat 'a') ("abcdef" ++ repeat 'b')+"abc" -} shorterListEq :: (Eq a) => [a] -> [a] -> [a] shorterListEq xs ys =
+ src/Data/List/Reverse/Private.hs view
@@ -0,0 +1,50 @@+module Data.List.Reverse.Private where++import qualified Data.List.Key.Private as Key+import Data.List.HT (segmentAfter, viewR, groupBy)++import Prelude hiding (dropWhile, takeWhile)+++-- $setup+-- >>> import Test.Utility (forAllPredicates)+-- >>> import qualified Data.List.Reverse.StrictElement as Rev+-- >>> import Prelude hiding (dropWhile, takeWhile)+++{- |+prop> forAllPredicates $ \p xs -> dropWhile p xs == Rev.dropWhile p xs+-}+dropWhile :: (a -> Bool) -> [a] -> [a]+dropWhile p =+ concat . init . segmentAfter (not . p)++{- |+prop> forAllPredicates $ \p xs -> takeWhile0 p xs == Rev.takeWhile p xs+-}+takeWhile0 :: (a -> Bool) -> [a] -> [a]+takeWhile0 p =+ last . segmentAfter (not . p)++{- |+Doesn't seem to be superior to the naive implementation.++prop> forAllPredicates $ \p xs -> takeWhile1 p xs == Rev.takeWhile p xs+-}+takeWhile1 :: (a -> Bool) -> [a] -> [a]+takeWhile1 p =+ (\mx ->+ case mx of+ Just (_, xs@((True,_):_)) -> map snd xs+ _ -> []) .+ viewR . Key.aux groupBy (==) p++{- |+However it is more inefficient,+because of repeatedly appending single elements. :-(++prop> forAllPredicates $ \p xs -> takeWhile2 p xs == Rev.takeWhile p xs+-}+takeWhile2 :: (a -> Bool) -> [a] -> [a]+takeWhile2 p =+ foldl (\xs x -> if p x then xs++[x] else []) []
src/Data/List/Reverse/StrictElement.hs view
@@ -12,10 +12,24 @@ import Prelude hiding (dropWhile, takeWhile, span, ) +-- $setup+-- >>> import Test.Utility (forAllPredicates, defined)+-- >>> import qualified Data.List.Reverse.StrictElement as Rev+-- >>> import qualified Data.List.Match as Match+-- >>> import qualified Data.List as List+-- >>> import Data.Tuple.HT (mapPair, swap)+-- >>>+-- >>> _suppressUnusedImportWarning :: (a -> Bool) -> [a] -> [a]+-- >>> _suppressUnusedImportWarning = Data.List.Reverse.StrictElement.dropWhile++ {- | Remove the longest suffix of elements satisfying p. In contrast to @reverse . dropWhile p . reverse@ this works for infinite lists, too.++prop> forAllPredicates $ \p xs -> Rev.dropWhile p xs == reverse (List.dropWhile p (reverse xs))+prop> \x xs pad -> defined $ Match.take (pad::[()]) $ Rev.dropWhile ((x::Char)/=) $ cycle $ x:xs -} dropWhile :: (a -> Bool) -> [a] -> [a] dropWhile p =@@ -23,6 +37,8 @@ {- | Alternative version of @reverse . takeWhile p . reverse@.++prop> forAllPredicates $ \p xs -> Rev.takeWhile p xs == reverse (List.takeWhile p (reverse xs)) -} takeWhile :: (a -> Bool) -> [a] -> [a] takeWhile p =@@ -33,7 +49,9 @@ (True, []) {- |-@span p xs == (dropWhile p xs, takeWhile p xs)@+prop> forAllPredicates $ \p xs -> Rev.span p xs == swap (mapPair (reverse, reverse) (List.span p (reverse xs)))+prop> forAllPredicates $ \p xs -> Rev.span p xs == (Rev.dropWhile p xs, Rev.takeWhile p xs)+prop> \x xs pad -> defined $ Match.take (pad::[()]) $ fst $ Rev.span ((x::Char)/=) $ cycle $ x:xs -} span :: (a -> Bool) -> [a] -> ([a], [a]) span p =
src/Data/List/Reverse/StrictSpine.hs view
@@ -1,7 +1,7 @@ {- | The functions in this module process the list from the end. They do not access elements at the beginning if not necessary.-You can apply the function only to infinite lists.+You can apply the function only to finite lists. Use these functions if the list is short and the test is expensive. -} module Data.List.Reverse.StrictSpine where@@ -11,15 +11,28 @@ import Prelude hiding (dropWhile, takeWhile, span, ) +-- $setup+-- >>> import Test.Utility (forAllPredicates, defined)+-- >>> import qualified Data.List.Reverse.StrictSpine as Rev+-- >>> import qualified Data.List.Match as Match+-- >>> import qualified Data.List as List+-- >>> import Data.Tuple.HT (mapFst, mapPair, swap)+-- >>>+-- >>> _suppressUnusedImportWarning :: (a -> Bool) -> [a] -> [a]+-- >>> _suppressUnusedImportWarning = Data.List.Reverse.StrictSpine.dropWhile++ {- |-Like @reverse . List.dropWhile p . reverse@.+prop> forAllPredicates $ \p xs -> Rev.dropWhile p xs == reverse (List.dropWhile p (reverse xs))+prop> \x xs pad -> defined $ length $ Rev.dropWhile ((x::Char)/=) $ Match.replicate (pad::[()]) undefined ++ x:xs -} dropWhile :: (a -> Bool) -> [a] -> [a] dropWhile p = foldr (\x xs -> if null xs && p x then [] else x:xs) [] {- |-Like @reverse . List.takeWhile p . reverse@.+prop> forAllPredicates $ \p xs -> Rev.takeWhile p xs == reverse (List.takeWhile p (reverse xs))+prop> \x xs pad -> defined $ Rev.takeWhile ((x::Char)/=) $ Match.replicate (pad::[()]) undefined ++ x:xs -} takeWhile :: (a -> Bool) -> [a] -> [a] takeWhile p =@@ -30,7 +43,9 @@ (True, []) {- |-@span p xs == (dropWhile p xs, takeWhile p xs)@+prop> forAllPredicates $ \p xs -> Rev.span p xs == swap (mapPair (reverse, reverse) (List.span p (reverse xs)))+prop> forAllPredicates $ \p xs -> Rev.span p xs == (Rev.dropWhile p xs, Rev.takeWhile p xs)+prop> \x xs pad -> defined $ mapFst length $ Rev.span ((x::Char)/=) $ Match.replicate (pad::[()]) undefined ++ x:xs -} span :: (a -> Bool) -> [a] -> ([a], [a]) span p =
src/Data/Maybe/HT.hs view
@@ -3,11 +3,17 @@ import Data.Maybe (fromMaybe, ) import Control.Monad (msum, ) +{- $setup+>>> import Control.Monad (guard)+-}+ {- It was proposed as addition to Data.Maybe and rejected at that time. <http://www.haskell.org/pipermail/libraries/2004-July/002381.html> -}-{- | Returns 'Just' if the precondition is fulfilled. -}+{- | Returns 'Just' if the precondition is fulfilled.+prop> \b x -> (guard b >> x) == (toMaybe b =<< (x::Maybe Char))+-} {-# INLINE toMaybe #-} toMaybe :: Bool -> a -> Maybe a toMaybe False _ = Nothing
src/Data/Monoid/HT.hs view
@@ -1,11 +1,18 @@-module Data.Monoid.HT (cycle, (<>), when, ) where+module Data.Monoid.HT (cycle, (<>), when, power) where import Data.Monoid (Monoid, mappend, mempty, ) import Data.Function (fix, ) -import Prelude (Bool)+import Prelude (Integer, Bool, Ordering(..), compare, divMod, error) +{- $setup+>>> import qualified Test.QuickCheck as QC+>>> import Control.Monad (mfilter)+>>> import Data.Function.HT (powerAssociative)+>>> import Data.Monoid (mconcat, mappend, mempty)+-}+ {- | Generalization of 'Data.List.cycle' to any monoid. -}@@ -23,5 +30,30 @@ (<>) = mappend +{- |+prop> \b m -> when b m == mfilter (const b) (m::Maybe Ordering)+prop> \b m -> when b m == mfilter (const b) (m::String)+-} when :: Monoid m => Bool -> m -> m when b m = if b then m else mempty++{- |+prop> QC.forAll (QC.choose (0,20)) $ \k xs -> power (fromIntegral k) xs == mconcat (replicate k (xs::String))++In contrast to 'powerAssociative' the 'power' function+uses 'mempty' only for the zeroth power.++prop> QC.forAll (QC.choose (0,20)) $ \k xs -> power k xs == powerAssociative mappend mempty (xs::String) k+-}+power :: Monoid m => Integer -> m -> m+power k m =+ case compare k 0 of+ LT -> error "Monoid.power: negative exponent"+ EQ -> mempty+ GT ->+ let (k2,r) = divMod k 2+ p = power k2 m+ p2 = p<>p+ in case r of+ 0 -> p2+ _ -> m<>p2
+ src/DocTest/Data/Bool/HT/Private.hs view
@@ -0,0 +1,27 @@+-- Do not edit! Automatically created with doctest-extract from src/Data/Bool/HT/Private.hs+module DocTest.Data.Bool.HT.Private where++import Data.Bool.HT.Private+import Test.DocTest.Base+import qualified Test.DocTest.Driver as DocTest+++test :: DocTest.T ()+test = do+ DocTest.printPrefix "Data.Bool.HT.Private:55: "+{-# LINE 55 "src/Data/Bool/HT/Private.hs" #-}+ DocTest.example+{-# LINE 55 "src/Data/Bool/HT/Private.hs" #-}+ (True ?: ("yes", "no"))+ [ExpectedLine [LineChunk "\"yes\""]]+ DocTest.printPrefix "Data.Bool.HT.Private:57: "+{-# LINE 57 "src/Data/Bool/HT/Private.hs" #-}+ DocTest.example+{-# LINE 57 "src/Data/Bool/HT/Private.hs" #-}+ (False ?: ("yes", "no"))+ [ExpectedLine [LineChunk "\"no\""]]+ DocTest.printPrefix "Data.Bool.HT.Private:73: "+{-# LINE 73 "src/Data/Bool/HT/Private.hs" #-}+ DocTest.property+{-# LINE 73 "src/Data/Bool/HT/Private.hs" #-}+ (\a b -> implies a b == (a<=b))
+ src/DocTest/Data/Function/HT/Private.hs view
@@ -0,0 +1,33 @@+-- Do not edit! Automatically created with doctest-extract from src/Data/Function/HT/Private.hs+{-# LINE 7 "src/Data/Function/HT/Private.hs" #-}++module DocTest.Data.Function.HT.Private where++import Data.Function.HT.Private+import qualified Test.DocTest.Driver as DocTest++{-# LINE 8 "src/Data/Function/HT/Private.hs" #-}+import Test.QuickCheck (NonNegative(NonNegative))++test :: DocTest.T ()+test = do+ DocTest.printPrefix "Data.Function.HT.Private:22: "+{-# LINE 22 "src/Data/Function/HT/Private.hs" #-}+ DocTest.property+{-# LINE 22 "src/Data/Function/HT/Private.hs" #-}+ (\(NonNegative n) x -> nest n succ x == nest1 n succ (x::Integer))+ DocTest.printPrefix "Data.Function.HT.Private:23: "+{-# LINE 23 "src/Data/Function/HT/Private.hs" #-}+ DocTest.property+{-# LINE 23 "src/Data/Function/HT/Private.hs" #-}+ (\(NonNegative n) x -> nest n succ x == nest2 n succ (x::Integer))+ DocTest.printPrefix "Data.Function.HT.Private:48: "+{-# LINE 48 "src/Data/Function/HT/Private.hs" #-}+ DocTest.property+{-# LINE 48 "src/Data/Function/HT/Private.hs" #-}+ (\a0 a (NonNegative n) -> powerAssociative (+) a0 a n == (powerAssociativeList (+) a0 a n :: Integer))+ DocTest.printPrefix "Data.Function.HT.Private:49: "+{-# LINE 49 "src/Data/Function/HT/Private.hs" #-}+ DocTest.property+{-# LINE 49 "src/Data/Function/HT/Private.hs" #-}+ (\a0 a (NonNegative n) -> powerAssociative (+) a0 a n == (powerAssociativeNaive (+) a0 a n :: Integer))
+ src/DocTest/Data/List/HT/Private.hs view
@@ -0,0 +1,658 @@+-- Do not edit! Automatically created with doctest-extract from src/Data/List/HT/Private.hs+{-# LINE 21 "src/Data/List/HT/Private.hs" #-}++module DocTest.Data.List.HT.Private where++import Data.List.HT.Private+import Test.DocTest.Base+import qualified Test.DocTest.Driver as DocTest++{-# LINE 22 "src/Data/List/HT/Private.hs" #-}+import qualified Test.QuickCheck as QC+import Test.Utility (forAllPredicates)+import Test.QuickCheck (NonNegative(NonNegative), Positive(Positive), NonEmptyList(NonEmpty))+import qualified Data.List as List+import Data.List (transpose)+import Data.Maybe.HT (toMaybe)+import Data.Maybe (mapMaybe, isNothing)+import Data.Char (isLetter, toUpper)+import Data.Eq.HT (equating)+import Control.Monad (liftM2)++divMaybe :: Int -> Int -> Maybe Int+divMaybe m n = case divMod n m of (q,0) -> Just q; _ -> Nothing++forAllMaybeFn :: (QC.Testable test) => ((Int -> Maybe Int) -> test) -> QC.Property+forAllMaybeFn prop = QC.forAll (QC.choose (1,4)) $ prop . divMaybe++test :: DocTest.T ()+test = do+ DocTest.printPrefix "Data.List.HT.Private:101: "+{-# LINE 101 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 101 "src/Data/List/HT/Private.hs" #-}+ (groupBy (<) "abcdebcdef")+ [ExpectedLine [LineChunk "[\"abcde\",\"bcdef\"]"]]+ DocTest.printPrefix "Data.List.HT.Private:108: "+{-# LINE 108 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 108 "src/Data/List/HT/Private.hs" #-}+ (List.groupBy (<) "abcdebcdef")+ [ExpectedLine [LineChunk "[\"abcdebcdef\"]"]]+ DocTest.printPrefix "Data.List.HT.Private:179: "+{-# LINE 179 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 179 "src/Data/List/HT/Private.hs" #-}+ (words "a a")+ [ExpectedLine [LineChunk "[\"a\",\"a\"]"]]+ DocTest.printPrefix "Data.List.HT.Private:181: "+{-# LINE 181 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 181 "src/Data/List/HT/Private.hs" #-}+ (chop (' '==) "a a")+ [ExpectedLine [LineChunk "[\"a\",\"\",\"a\"]"]]+ DocTest.printPrefix "Data.List.HT.Private:184: "+{-# LINE 184 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 184 "src/Data/List/HT/Private.hs" #-}+ (lines "a\n\na")+ [ExpectedLine [LineChunk "[\"a\",\"\",\"a\"]"]]+ DocTest.printPrefix "Data.List.HT.Private:186: "+{-# LINE 186 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 186 "src/Data/List/HT/Private.hs" #-}+ (chop ('\n'==) "a\n\na")+ [ExpectedLine [LineChunk "[\"a\",\"\",\"a\"]"]]+ DocTest.printPrefix "Data.List.HT.Private:189: "+{-# LINE 189 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 189 "src/Data/List/HT/Private.hs" #-}+ (lines "a\n")+ [ExpectedLine [LineChunk "[\"a\"]"]]+ DocTest.printPrefix "Data.List.HT.Private:191: "+{-# LINE 191 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 191 "src/Data/List/HT/Private.hs" #-}+ (chop ('\n'==) "a\n")+ [ExpectedLine [LineChunk "[\"a\",\"\"]"]]+ DocTest.printPrefix "Data.List.HT.Private:220: "+{-# LINE 220 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 220 "src/Data/List/HT/Private.hs" #-}+ (forAllPredicates $ \p xs -> uncurry (++) (breakAfter p xs) == xs)+ DocTest.printPrefix "Data.List.HT.Private:239: "+{-# LINE 239 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 239 "src/Data/List/HT/Private.hs" #-}+ (forAllPredicates $ \p xs -> breakAfterRec p xs == breakAfterFoldr p xs)+ DocTest.printPrefix "Data.List.HT.Private:247: "+{-# LINE 247 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 247 "src/Data/List/HT/Private.hs" #-}+ (forAllPredicates $ \p xs -> breakAfterRec p xs == breakAfterBreak p xs)+ DocTest.printPrefix "Data.List.HT.Private:254: "+{-# LINE 254 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 254 "src/Data/List/HT/Private.hs" #-}+ (forAllPredicates $ \p xs -> breakAfterRec p xs == breakAfterTakeUntil p xs)+ DocTest.printPrefix "Data.List.HT.Private:267: "+{-# LINE 267 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 267 "src/Data/List/HT/Private.hs" #-}+ (forAllPredicates $ \p xs -> takeUntil p xs == fst (breakAfter p xs))+ DocTest.printPrefix "Data.List.HT.Private:280: "+{-# LINE 280 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 280 "src/Data/List/HT/Private.hs" #-}+ (forAllPredicates $ \p xs -> concat (segmentAfter p xs) == xs)+ DocTest.printPrefix "Data.List.HT.Private:281: "+{-# LINE 281 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 281 "src/Data/List/HT/Private.hs" #-}+ (forAllPredicates $ \p xs -> length (filter p xs) == length (tail (segmentAfter p xs)))+ DocTest.printPrefix "Data.List.HT.Private:282: "+{-# LINE 282 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 282 "src/Data/List/HT/Private.hs" #-}+ (forAllPredicates $ \p -> all (p . last) . init . segmentAfter p)+ DocTest.printPrefix "Data.List.HT.Private:283: "+{-# LINE 283 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 283 "src/Data/List/HT/Private.hs" #-}+ (forAllPredicates $ \p -> all (all (not . p) . init) . init . segmentAfter p)+ DocTest.printPrefix "Data.List.HT.Private:287: "+{-# LINE 287 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 287 "src/Data/List/HT/Private.hs" #-}+ (forAllPredicates $ \p x -> flip seq True . (!!100) . concat . segmentAfter p . cycle . (x:))+ DocTest.printPrefix "Data.List.HT.Private:309: "+{-# LINE 309 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 309 "src/Data/List/HT/Private.hs" #-}+ (forAllPredicates $ \p xs -> concat (segmentBefore p xs) == xs)+ DocTest.printPrefix "Data.List.HT.Private:310: "+{-# LINE 310 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 310 "src/Data/List/HT/Private.hs" #-}+ (forAllPredicates $ \p xs -> length (filter p xs) == length (tail (segmentBefore p xs)))+ DocTest.printPrefix "Data.List.HT.Private:311: "+{-# LINE 311 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 311 "src/Data/List/HT/Private.hs" #-}+ (forAllPredicates $ \p -> all (p . head) . tail . segmentBefore p)+ DocTest.printPrefix "Data.List.HT.Private:312: "+{-# LINE 312 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 312 "src/Data/List/HT/Private.hs" #-}+ (forAllPredicates $ \p -> all (all (not . p) . tail) . tail . segmentBefore p)+ DocTest.printPrefix "Data.List.HT.Private:313: "+{-# LINE 313 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 313 "src/Data/List/HT/Private.hs" #-}+ (forAllPredicates $ \p x -> flip seq True . (!!100) . concat . segmentBefore p . cycle . (x:))+ DocTest.printPrefix "Data.List.HT.Private:325: "+{-# LINE 325 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 325 "src/Data/List/HT/Private.hs" #-}+ (forAllPredicates $ \p xs -> segmentBefore p xs == segmentBefore' p xs)+ DocTest.printPrefix "Data.List.HT.Private:336: "+{-# LINE 336 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 336 "src/Data/List/HT/Private.hs" #-}+ (forAllPredicates $ \p xs -> segmentBefore p xs == segmentBefore'' p xs)+ DocTest.printPrefix "Data.List.HT.Private:348: "+{-# LINE 348 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 348 "src/Data/List/HT/Private.hs" #-}+ (segmentBeforeJust (\c -> toMaybe (isLetter c) (toUpper c)) "123a5345b---")+ [ExpectedLine [LineChunk "(\"123\",[('A',\"5345\"),('B',\"---\")])"]]+ DocTest.printPrefix "Data.List.HT.Private:364: "+{-# LINE 364 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 364 "src/Data/List/HT/Private.hs" #-}+ (segmentAfterJust (\c -> toMaybe (isLetter c) (toUpper c)) "123a5345b---")+ [ExpectedLine [LineChunk "([(\"123\",'A'),(\"5345\",'B')],\"---\")"]]+ DocTest.printPrefix "Data.List.HT.Private:380: "+{-# LINE 380 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 380 "src/Data/List/HT/Private.hs" #-}+ (forAllMaybeFn $ \f xs -> segmentBeforeJust f xs == segmentBeforeRight (map (\x -> maybe (Left x) Right (f x)) xs))+ DocTest.printPrefix "Data.List.HT.Private:377: "+{-# LINE 377 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 377 "src/Data/List/HT/Private.hs" #-}+ (segmentBeforeRight [Left 'a', Right LT, Right GT, Left 'b'])+ [ExpectedLine [LineChunk "(\"a\",[(LT,\"\"),(GT,\"b\")])"]]+ DocTest.printPrefix "Data.List.HT.Private:397: "+{-# LINE 397 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 397 "src/Data/List/HT/Private.hs" #-}+ (forAllMaybeFn $ \f xs -> segmentAfterJust f xs == segmentAfterRight (map (\x -> maybe (Left x) Right (f x)) xs))+ DocTest.printPrefix "Data.List.HT.Private:394: "+{-# LINE 394 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 394 "src/Data/List/HT/Private.hs" #-}+ (segmentAfterRight [Left 'a', Right LT, Right GT, Left 'b'])+ [ExpectedLine [LineChunk "([(\"a\",LT),(\"\",GT)],\"b\")"]]+ DocTest.printPrefix "Data.List.HT.Private:420: "+{-# LINE 420 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 420 "src/Data/List/HT/Private.hs" #-}+ (removeEach "abc")+ [ExpectedLine [LineChunk "[('a',\"bc\"),('b',\"ac\"),('c',\"ab\")]"]]+ DocTest.printPrefix "Data.List.HT.Private:422: "+{-# LINE 422 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 422 "src/Data/List/HT/Private.hs" #-}+ (removeEach "a")+ [ExpectedLine [LineChunk "[('a',\"\")]"]]+ DocTest.printPrefix "Data.List.HT.Private:424: "+{-# LINE 424 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 424 "src/Data/List/HT/Private.hs" #-}+ (removeEach "")+ [ExpectedLine [LineChunk "[]"]]+ DocTest.printPrefix "Data.List.HT.Private:432: "+{-# LINE 432 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 432 "src/Data/List/HT/Private.hs" #-}+ (splitEverywhere "abc")+ [ExpectedLine [LineChunk "[(\"\",'a',\"bc\"),(\"a\",'b',\"c\"),(\"ab\",'c',\"\")]"]]+ DocTest.printPrefix "Data.List.HT.Private:434: "+{-# LINE 434 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 434 "src/Data/List/HT/Private.hs" #-}+ (splitEverywhere "a")+ [ExpectedLine [LineChunk "[(\"\",'a',\"\")]"]]+ DocTest.printPrefix "Data.List.HT.Private:436: "+{-# LINE 436 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 436 "src/Data/List/HT/Private.hs" #-}+ (splitEverywhere "")+ [ExpectedLine [LineChunk "[]"]]+ DocTest.printPrefix "Data.List.HT.Private:459: "+{-# LINE 459 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 459 "src/Data/List/HT/Private.hs" #-}+ (\(NonEmpty xs) -> splitLast (xs::String) == (init xs, last xs))+ DocTest.printPrefix "Data.List.HT.Private:479: "+{-# LINE 479 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 479 "src/Data/List/HT/Private.hs" #-}+ (\xs -> maybe True ((init xs, last xs) == ) (viewR (xs::String)))+ DocTest.printPrefix "Data.List.HT.Private:500: "+{-# LINE 500 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 500 "src/Data/List/HT/Private.hs" #-}+ (\xs -> switchR True (\ixs lxs -> ixs == init xs && lxs == last xs) (xs::String))+ DocTest.printPrefix "Data.List.HT.Private:514: "+{-# LINE 514 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 514 "src/Data/List/HT/Private.hs" #-}+ (\n xs -> takeRev n (xs::String) == reverse (take n (reverse xs)))+ DocTest.printPrefix "Data.List.HT.Private:523: "+{-# LINE 523 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 523 "src/Data/List/HT/Private.hs" #-}+ (\n xs -> dropRev n (xs::String) == reverse (drop n (reverse xs)))+ DocTest.printPrefix "Data.List.HT.Private:531: "+{-# LINE 531 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 531 "src/Data/List/HT/Private.hs" #-}+ (\n xs -> splitAtRev n (xs::String) == (dropRev n xs, takeRev n xs))+ DocTest.printPrefix "Data.List.HT.Private:532: "+{-# LINE 532 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 532 "src/Data/List/HT/Private.hs" #-}+ (\n xs -> (xs::String) == uncurry (++) (splitAtRev n xs))+ DocTest.printPrefix "Data.List.HT.Private:546: "+{-# LINE 546 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 546 "src/Data/List/HT/Private.hs" #-}+ (maybePrefixOf "abc" "abcdef")+ [ExpectedLine [LineChunk "Just \"def\""]]+ DocTest.printPrefix "Data.List.HT.Private:548: "+{-# LINE 548 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 548 "src/Data/List/HT/Private.hs" #-}+ (maybePrefixOf "def" "abcdef")+ [ExpectedLine [LineChunk "Nothing"]]+ DocTest.printPrefix "Data.List.HT.Private:557: "+{-# LINE 557 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 557 "src/Data/List/HT/Private.hs" #-}+ (maybeSuffixOf "abc" "abcdef")+ [ExpectedLine [LineChunk "Nothing"]]+ DocTest.printPrefix "Data.List.HT.Private:559: "+{-# LINE 559 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 559 "src/Data/List/HT/Private.hs" #-}+ (maybeSuffixOf "def" "abcdef")+ [ExpectedLine [LineChunk "Just \"abc\""]]+ DocTest.printPrefix "Data.List.HT.Private:570: "+{-# LINE 570 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 570 "src/Data/List/HT/Private.hs" #-}+ (forAllMaybeFn $ \f xs -> partitionMaybe f xs == (mapMaybe f xs, filter (isNothing . f) xs))+ DocTest.printPrefix "Data.List.HT.Private:571: "+{-# LINE 571 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 571 "src/Data/List/HT/Private.hs" #-}+ (forAllPredicates $ \p xs -> partition p xs == partitionMaybe (\x -> toMaybe (p x) x) xs)+ DocTest.printPrefix "Data.List.HT.Private:584: "+{-# LINE 584 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 584 "src/Data/List/HT/Private.hs" #-}+ (takeWhileJust [Just 'a', Just 'b', Nothing, Just 'c'])+ [ExpectedLine [LineChunk "\"ab\""]]+ DocTest.printPrefix "Data.List.HT.Private:589: "+{-# LINE 589 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 589 "src/Data/List/HT/Private.hs" #-}+ (takeWhileJust $ map (fmap fst . viewL) ["abc","def","","xyz"])+ [ExpectedLine [LineChunk "\"ad\""]]+ DocTest.printPrefix "Data.List.HT.Private:610: "+{-# LINE 610 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 610 "src/Data/List/HT/Private.hs" #-}+ (forAllMaybeFn $ \f xs -> dropWhileNothing f xs == dropWhileNothingRec f xs)+ DocTest.printPrefix "Data.List.HT.Private:617: "+{-# LINE 617 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 617 "src/Data/List/HT/Private.hs" #-}+ (forAllMaybeFn $ \f xs -> snd (breakJust f xs) == dropWhileNothing f xs)+ DocTest.printPrefix "Data.List.HT.Private:628: "+{-# LINE 628 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 628 "src/Data/List/HT/Private.hs" #-}+ (forAllMaybeFn $ \f xs -> breakJust f xs == breakJustRemoveEach f xs)+ DocTest.printPrefix "Data.List.HT.Private:636: "+{-# LINE 636 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 636 "src/Data/List/HT/Private.hs" #-}+ (forAllMaybeFn $ \f xs -> breakJust f xs == breakJustPartial f xs)+ DocTest.printPrefix "Data.List.HT.Private:664: "+{-# LINE 664 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 664 "src/Data/List/HT/Private.hs" #-}+ (sieve 6 ['a'..'z'])+ [ExpectedLine [LineChunk "\"agmsy\""]]+ DocTest.printPrefix "Data.List.HT.Private:671: "+{-# LINE 671 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 671 "src/Data/List/HT/Private.hs" #-}+ (\(Positive n) xs -> sieve n xs == sieve' n (xs::String))+ DocTest.printPrefix "Data.List.HT.Private:674: "+{-# LINE 674 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 674 "src/Data/List/HT/Private.hs" #-}+ (\(Positive n) xs -> sieve n xs == sieve'' n (xs::String))+ DocTest.printPrefix "Data.List.HT.Private:677: "+{-# LINE 677 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 677 "src/Data/List/HT/Private.hs" #-}+ (\(Positive n) xs -> sieve n xs == sieve''' n (xs::String))+ DocTest.printPrefix "Data.List.HT.Private:689: "+{-# LINE 689 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 689 "src/Data/List/HT/Private.hs" #-}+ (\(NonEmpty xs) -> QC.forAll (QC.choose (1, length xs)) $ \n -> sliceHorizontal n xs == transpose (sliceVertical n (xs::String)))+ DocTest.printPrefix "Data.List.HT.Private:690: "+{-# LINE 690 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 690 "src/Data/List/HT/Private.hs" #-}+ (\(NonEmpty xs) -> QC.forAll (QC.choose (1, length xs)) $ \n -> sliceVertical n xs == transpose (sliceHorizontal n (xs::String)))+ DocTest.printPrefix "Data.List.HT.Private:686: "+{-# LINE 686 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 686 "src/Data/List/HT/Private.hs" #-}+ (sliceHorizontal 6 ['a'..'z'])+ [ExpectedLine [LineChunk "[\"agmsy\",\"bhntz\",\"ciou\",\"djpv\",\"ekqw\",\"flrx\"]"]]+ DocTest.printPrefix "Data.List.HT.Private:694: "+{-# LINE 694 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 694 "src/Data/List/HT/Private.hs" #-}+ (sliceHorizontal 4 ([]::[Int]))+ [ExpectedLine [LineChunk "[[],[],[],[]]"]]+ DocTest.printPrefix "Data.List.HT.Private:702: "+{-# LINE 702 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 702 "src/Data/List/HT/Private.hs" #-}+ (\(NonNegative n) xs -> sliceHorizontal n xs == sliceHorizontal' n (xs::String))+ DocTest.printPrefix "Data.List.HT.Private:706: "+{-# LINE 706 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 706 "src/Data/List/HT/Private.hs" #-}+ (\(Positive n) xs -> sliceHorizontal n xs == sliceHorizontal'' n (xs::String))+ DocTest.printPrefix "Data.List.HT.Private:715: "+{-# LINE 715 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 715 "src/Data/List/HT/Private.hs" #-}+ (sliceVertical 6 ['a'..'z'])+ [ExpectedLine [LineChunk "[\"abcdef\",\"ghijkl\",\"mnopqr\",\"stuvwx\",\"yz\"]"]]+ DocTest.printPrefix "Data.List.HT.Private:724: "+{-# LINE 724 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 724 "src/Data/List/HT/Private.hs" #-}+ (\(NonNegative n) xs -> equating (take 100000) (sliceVertical n xs) (sliceVertical' n (xs::String)))+ DocTest.printPrefix "Data.List.HT.Private:737: "+{-# LINE 737 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 737 "src/Data/List/HT/Private.hs" #-}+ (\(NonEmpty xs) ys -> replace xs xs ys == (ys::String))+ DocTest.printPrefix "Data.List.HT.Private:738: "+{-# LINE 738 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 738 "src/Data/List/HT/Private.hs" #-}+ (\(NonEmpty xs) (NonEmpty ys) -> equating (take 1000) (replace xs ys (cycle xs)) (cycle (ys::String)))+ DocTest.printPrefix "Data.List.HT.Private:876: "+{-# LINE 876 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 876 "src/Data/List/HT/Private.hs" #-}+ (\xs -> shearTranspose xs == map reverse (shear (xs::[String])))+ DocTest.printPrefix "Data.List.HT.Private:911: "+{-# LINE 911 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 911 "src/Data/List/HT/Private.hs" #-}+ (\xs ys -> let f x y = (x::Char,y::Int) in concat (outerProduct f xs ys) == liftM2 f xs ys)+ DocTest.printPrefix "Data.List.HT.Private:934: "+{-# LINE 934 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 934 "src/Data/List/HT/Private.hs" #-}+ (\ys xs -> let ps = map (<=) ys in takeWhileMulti ps xs == takeWhileMulti' ps (xs::String))+ DocTest.printPrefix "Data.List.HT.Private:999: "+{-# LINE 999 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 999 "src/Data/List/HT/Private.hs" #-}+ (\n xs -> lengthAtLeast n (xs::String) == (length xs >= n))+ DocTest.printPrefix "Data.List.HT.Private:988: "+{-# LINE 988 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 988 "src/Data/List/HT/Private.hs" #-}+ (lengthAtLeast 0 "")+ [ExpectedLine [LineChunk "True"]]+ DocTest.printPrefix "Data.List.HT.Private:990: "+{-# LINE 990 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 990 "src/Data/List/HT/Private.hs" #-}+ (lengthAtLeast 3 "ab")+ [ExpectedLine [LineChunk "False"]]+ DocTest.printPrefix "Data.List.HT.Private:992: "+{-# LINE 992 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 992 "src/Data/List/HT/Private.hs" #-}+ (lengthAtLeast 3 "abc")+ [ExpectedLine [LineChunk "True"]]+ DocTest.printPrefix "Data.List.HT.Private:994: "+{-# LINE 994 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 994 "src/Data/List/HT/Private.hs" #-}+ (lengthAtLeast 3 $ repeat 'a')+ [ExpectedLine [LineChunk "True"]]+ DocTest.printPrefix "Data.List.HT.Private:996: "+{-# LINE 996 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 996 "src/Data/List/HT/Private.hs" #-}+ (lengthAtLeast 3 $ "abc" ++ undefined)+ [ExpectedLine [LineChunk "True"]]+ DocTest.printPrefix "Data.List.HT.Private:1021: "+{-# LINE 1021 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 1021 "src/Data/List/HT/Private.hs" #-}+ (\n xs -> lengthAtMost n (xs::String) == (length xs <= n))+ DocTest.printPrefix "Data.List.HT.Private:1008: "+{-# LINE 1008 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 1008 "src/Data/List/HT/Private.hs" #-}+ (lengthAtMost 0 "")+ [ExpectedLine [LineChunk "True"]]+ DocTest.printPrefix "Data.List.HT.Private:1010: "+{-# LINE 1010 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 1010 "src/Data/List/HT/Private.hs" #-}+ (lengthAtMost 3 "ab")+ [ExpectedLine [LineChunk "True"]]+ DocTest.printPrefix "Data.List.HT.Private:1012: "+{-# LINE 1012 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 1012 "src/Data/List/HT/Private.hs" #-}+ (lengthAtMost 3 "abc")+ [ExpectedLine [LineChunk "True"]]+ DocTest.printPrefix "Data.List.HT.Private:1014: "+{-# LINE 1014 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 1014 "src/Data/List/HT/Private.hs" #-}+ (lengthAtMost 3 "abcd")+ [ExpectedLine [LineChunk "False"]]+ DocTest.printPrefix "Data.List.HT.Private:1016: "+{-# LINE 1016 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 1016 "src/Data/List/HT/Private.hs" #-}+ (lengthAtMost 3 $ repeat 'a')+ [ExpectedLine [LineChunk "False"]]+ DocTest.printPrefix "Data.List.HT.Private:1018: "+{-# LINE 1018 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 1018 "src/Data/List/HT/Private.hs" #-}+ (lengthAtMost 3 $ "abcd" ++ undefined)+ [ExpectedLine [LineChunk "False"]]+ DocTest.printPrefix "Data.List.HT.Private:1030: "+{-# LINE 1030 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 1030 "src/Data/List/HT/Private.hs" #-}+ (\n xs -> lengthAtMost0 n (xs::String) == (length xs <= n))+ DocTest.printPrefix "Data.List.HT.Private:1077: "+{-# LINE 1077 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 1077 "src/Data/List/HT/Private.hs" #-}+ (\(NonNegative n) (NonEmpty xs) -> rotate n xs == rotate' n (xs::String))+ DocTest.printPrefix "Data.List.HT.Private:1084: "+{-# LINE 1084 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 1084 "src/Data/List/HT/Private.hs" #-}+ (\(NonNegative n) xs -> rotate n xs == rotate'' n (xs::String))+ DocTest.printPrefix "Data.List.HT.Private:1094: "+{-# LINE 1094 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 1094 "src/Data/List/HT/Private.hs" #-}+ (mergeBy (<=) "agh" "begz")+ [ExpectedLine [LineChunk "\"abegghz\""]]+ DocTest.printPrefix "Data.List.HT.Private:1102: "+{-# LINE 1102 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 1102 "src/Data/List/HT/Private.hs" #-}+ (allEqual "aab")+ [ExpectedLine [LineChunk "False"]]+ DocTest.printPrefix "Data.List.HT.Private:1104: "+{-# LINE 1104 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 1104 "src/Data/List/HT/Private.hs" #-}+ (allEqual "aaa")+ [ExpectedLine [LineChunk "True"]]+ DocTest.printPrefix "Data.List.HT.Private:1106: "+{-# LINE 1106 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 1106 "src/Data/List/HT/Private.hs" #-}+ (allEqual "aa")+ [ExpectedLine [LineChunk "True"]]+ DocTest.printPrefix "Data.List.HT.Private:1108: "+{-# LINE 1108 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 1108 "src/Data/List/HT/Private.hs" #-}+ (allEqual "a")+ [ExpectedLine [LineChunk "True"]]+ DocTest.printPrefix "Data.List.HT.Private:1110: "+{-# LINE 1110 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 1110 "src/Data/List/HT/Private.hs" #-}+ (allEqual "")+ [ExpectedLine [LineChunk "True"]]+ DocTest.printPrefix "Data.List.HT.Private:1117: "+{-# LINE 1117 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 1117 "src/Data/List/HT/Private.hs" #-}+ (isAscending "abc")+ [ExpectedLine [LineChunk "True"]]+ DocTest.printPrefix "Data.List.HT.Private:1119: "+{-# LINE 1119 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 1119 "src/Data/List/HT/Private.hs" #-}+ (isAscending "abb")+ [ExpectedLine [LineChunk "True"]]+ DocTest.printPrefix "Data.List.HT.Private:1121: "+{-# LINE 1121 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 1121 "src/Data/List/HT/Private.hs" #-}+ (isAscending "aba")+ [ExpectedLine [LineChunk "False"]]+ DocTest.printPrefix "Data.List.HT.Private:1123: "+{-# LINE 1123 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 1123 "src/Data/List/HT/Private.hs" #-}+ (isAscending "cba")+ [ExpectedLine [LineChunk "False"]]+ DocTest.printPrefix "Data.List.HT.Private:1125: "+{-# LINE 1125 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 1125 "src/Data/List/HT/Private.hs" #-}+ (isAscending "a")+ [ExpectedLine [LineChunk "True"]]+ DocTest.printPrefix "Data.List.HT.Private:1127: "+{-# LINE 1127 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 1127 "src/Data/List/HT/Private.hs" #-}+ (isAscending "")+ [ExpectedLine [LineChunk "True"]]+ DocTest.printPrefix "Data.List.HT.Private:1149: "+{-# LINE 1149 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 1149 "src/Data/List/HT/Private.hs" #-}+ (\x xs -> mapAdjacent subtract (scanl (+) x xs) == (xs::[Integer]))+ DocTest.printPrefix "Data.List.HT.Private:1140: "+{-# LINE 1140 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 1140 "src/Data/List/HT/Private.hs" #-}+ (mapAdjacent (<=) "")+ [ExpectedLine [LineChunk "[]"]]+ DocTest.printPrefix "Data.List.HT.Private:1142: "+{-# LINE 1142 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 1142 "src/Data/List/HT/Private.hs" #-}+ (mapAdjacent (<=) "a")+ [ExpectedLine [LineChunk "[]"]]+ DocTest.printPrefix "Data.List.HT.Private:1144: "+{-# LINE 1144 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 1144 "src/Data/List/HT/Private.hs" #-}+ (mapAdjacent (<=) "aba")+ [ExpectedLine [LineChunk "[True,False]"]]+ DocTest.printPrefix "Data.List.HT.Private:1146: "+{-# LINE 1146 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 1146 "src/Data/List/HT/Private.hs" #-}+ (mapAdjacent (,) "abc")+ [ExpectedLine [LineChunk "[('a','b'),('b','c')]"]]+ DocTest.printPrefix "Data.List.HT.Private:1157: "+{-# LINE 1157 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 1157 "src/Data/List/HT/Private.hs" #-}+ (\xs -> mapAdjacent (,) xs == mapAdjacentPointfree (,) (xs::String))+ DocTest.printPrefix "Data.List.HT.Private:1164: "+{-# LINE 1164 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 1164 "src/Data/List/HT/Private.hs" #-}+ (let f x y z = [x,y]++show(z::Int) in mapAdjacent1 f 'a' [('b',1), ('c',2), ('d',3)])+ [ExpectedLine [LineChunk "[\"ab1\",\"bc2\",\"cd3\"]"]]+ DocTest.printPrefix "Data.List.HT.Private:1183: "+{-# LINE 1183 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 1183 "src/Data/List/HT/Private.hs" #-}+ (\(NonNegative n) -> length (range n :: [Integer]) == n)+ DocTest.printPrefix "Data.List.HT.Private:1176: "+{-# LINE 1176 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 1176 "src/Data/List/HT/Private.hs" #-}+ (range 0 :: [Integer])+ [ExpectedLine [LineChunk "[]"]]+ DocTest.printPrefix "Data.List.HT.Private:1178: "+{-# LINE 1178 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 1178 "src/Data/List/HT/Private.hs" #-}+ (range 1 :: [Integer])+ [ExpectedLine [LineChunk "[0]"]]+ DocTest.printPrefix "Data.List.HT.Private:1180: "+{-# LINE 1180 "src/Data/List/HT/Private.hs" #-}+ DocTest.example+{-# LINE 1180 "src/Data/List/HT/Private.hs" #-}+ (range 8 :: [Integer])+ [ExpectedLine [LineChunk "[0,1,2,3,4,5,6,7]"]]+ DocTest.printPrefix "Data.List.HT.Private:1210: "+{-# LINE 1210 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 1210 "src/Data/List/HT/Private.hs" #-}+ (\x -> equating (take 1000) (List.iterate (x+) x) (iterateAssociative (+) (x::Integer)))+ DocTest.printPrefix "Data.List.HT.Private:1229: "+{-# LINE 1229 "src/Data/List/HT/Private.hs" #-}+ DocTest.property+{-# LINE 1229 "src/Data/List/HT/Private.hs" #-}+ (\x -> equating (take 1000) (List.iterate (x+) x) (iterateLeaky (+) (x::Integer)))
+ src/DocTest/Data/List/Match/Private.hs view
@@ -0,0 +1,143 @@+-- Do not edit! Automatically created with doctest-extract from src/Data/List/Match/Private.hs+{-# LINE 15 "src/Data/List/Match/Private.hs" #-}++module DocTest.Data.List.Match.Private where++import Data.List.Match.Private+import Test.DocTest.Base+import qualified Test.DocTest.Driver as DocTest++{-# LINE 16 "src/Data/List/Match/Private.hs" #-}+import qualified Data.List.Match.Private as Match+import qualified Data.List as List++import qualified Test.QuickCheck as QC++newtype List = List [Integer] deriving (Show)+instance QC.Arbitrary List where+ arbitrary = fmap List QC.arbitrary+ shrink (List xs) = map List $ QC.shrink xs++newtype Shape = Shape [Ordering] deriving (Show)+instance QC.Arbitrary Shape where+ arbitrary = fmap Shape QC.arbitrary+ shrink (Shape xs) = map Shape $ QC.shrink xs++test :: DocTest.T ()+test = do+ DocTest.printPrefix "Data.List.Match.Private:34: "+{-# LINE 34 "src/Data/List/Match/Private.hs" #-}+ DocTest.property+{-# LINE 34 "src/Data/List/Match/Private.hs" #-}+ (\(Shape xs) (List ys) -> Match.take xs ys == List.take (length xs) ys)+ DocTest.printPrefix "Data.List.Match.Private:46: "+{-# LINE 46 "src/Data/List/Match/Private.hs" #-}+ DocTest.property+{-# LINE 46 "src/Data/List/Match/Private.hs" #-}+ (\(Shape xs) (List ys) -> Match.drop xs ys == List.drop (length xs) ys)+ DocTest.printPrefix "Data.List.Match.Private:47: "+{-# LINE 47 "src/Data/List/Match/Private.hs" #-}+ DocTest.property+{-# LINE 47 "src/Data/List/Match/Private.hs" #-}+ (\(Shape xs) (List ys) -> Match.take xs ys ++ Match.drop xs ys == ys)+ DocTest.printPrefix "Data.List.Match.Private:54: "+{-# LINE 54 "src/Data/List/Match/Private.hs" #-}+ DocTest.property+{-# LINE 54 "src/Data/List/Match/Private.hs" #-}+ (\(Shape xs) (List ys) -> Match.drop xs ys == dropRec xs ys)+ DocTest.printPrefix "Data.List.Match.Private:63: "+{-# LINE 63 "src/Data/List/Match/Private.hs" #-}+ DocTest.property+{-# LINE 63 "src/Data/List/Match/Private.hs" #-}+ (\(Shape xs) (List ys) -> Match.drop xs ys == drop0 xs ys)+ DocTest.printPrefix "Data.List.Match.Private:70: "+{-# LINE 70 "src/Data/List/Match/Private.hs" #-}+ DocTest.property+{-# LINE 70 "src/Data/List/Match/Private.hs" #-}+ (\(Shape xs) (List ys) -> Match.drop xs ys == drop1 xs ys)+ DocTest.printPrefix "Data.List.Match.Private:75: "+{-# LINE 75 "src/Data/List/Match/Private.hs" #-}+ DocTest.property+{-# LINE 75 "src/Data/List/Match/Private.hs" #-}+ (\(Shape xs) (List ys) -> Match.drop xs ys == drop2 xs ys)+ DocTest.printPrefix "Data.List.Match.Private:84: "+{-# LINE 84 "src/Data/List/Match/Private.hs" #-}+ DocTest.example+{-# LINE 84 "src/Data/List/Match/Private.hs" #-}+ (laxTail "")+ [ExpectedLine [LineChunk "\"\""]]+ DocTest.printPrefix "Data.List.Match.Private:86: "+{-# LINE 86 "src/Data/List/Match/Private.hs" #-}+ DocTest.example+{-# LINE 86 "src/Data/List/Match/Private.hs" #-}+ (laxTail "a")+ [ExpectedLine [LineChunk "\"\""]]+ DocTest.printPrefix "Data.List.Match.Private:88: "+{-# LINE 88 "src/Data/List/Match/Private.hs" #-}+ DocTest.example+{-# LINE 88 "src/Data/List/Match/Private.hs" #-}+ (laxTail "ab")+ [ExpectedLine [LineChunk "\"b\""]]+ DocTest.printPrefix "Data.List.Match.Private:94: "+{-# LINE 94 "src/Data/List/Match/Private.hs" #-}+ DocTest.property+{-# LINE 94 "src/Data/List/Match/Private.hs" #-}+ (\(List xs) -> Match.laxTail xs == Match.laxTail0 xs)+ DocTest.printPrefix "Data.List.Match.Private:99: "+{-# LINE 99 "src/Data/List/Match/Private.hs" #-}+ DocTest.property+{-# LINE 99 "src/Data/List/Match/Private.hs" #-}+ (\(Shape xs) (List ys) -> Match.splitAt xs ys == (Match.take xs ys, Match.drop xs ys))+ DocTest.printPrefix "Data.List.Match.Private:100: "+{-# LINE 100 "src/Data/List/Match/Private.hs" #-}+ DocTest.property+{-# LINE 100 "src/Data/List/Match/Private.hs" #-}+ (\(Shape xs) (List ys) -> Match.splitAt xs ys == List.splitAt (length xs) ys)+ DocTest.printPrefix "Data.List.Match.Private:110: "+{-# LINE 110 "src/Data/List/Match/Private.hs" #-}+ DocTest.property+{-# LINE 110 "src/Data/List/Match/Private.hs" #-}+ (\(Shape xs) (List ys) -> Match.takeRev xs ys == reverse (Match.take xs (reverse ys)))+ DocTest.printPrefix "Data.List.Match.Private:114: "+{-# LINE 114 "src/Data/List/Match/Private.hs" #-}+ DocTest.property+{-# LINE 114 "src/Data/List/Match/Private.hs" #-}+ (\(Shape xs) (List ys) -> Match.dropRev xs ys == reverse (Match.drop xs (reverse ys)))+ DocTest.printPrefix "Data.List.Match.Private:122: "+{-# LINE 122 "src/Data/List/Match/Private.hs" #-}+ DocTest.property+{-# LINE 122 "src/Data/List/Match/Private.hs" #-}+ (\(Shape xs) (List ys) -> equalLength xs ys == (length xs == length ys))+ DocTest.printPrefix "Data.List.Match.Private:134: "+{-# LINE 134 "src/Data/List/Match/Private.hs" #-}+ DocTest.property+{-# LINE 134 "src/Data/List/Match/Private.hs" #-}+ (\(Shape xs) (List ys) -> compareLength xs ys == compare (length xs) (length ys))+ DocTest.printPrefix "Data.List.Match.Private:144: "+{-# LINE 144 "src/Data/List/Match/Private.hs" #-}+ DocTest.property+{-# LINE 144 "src/Data/List/Match/Private.hs" #-}+ (\(Shape xs) (List ys) -> Match.compareLength xs ys == Match.compareLength0 xs ys)+ DocTest.printPrefix "Data.List.Match.Private:156: "+{-# LINE 156 "src/Data/List/Match/Private.hs" #-}+ DocTest.property+{-# LINE 156 "src/Data/List/Match/Private.hs" #-}+ (\(Shape xs) (List ys) -> Match.compareLength xs ys == Match.compareLength1 xs ys)+ DocTest.printPrefix "Data.List.Match.Private:166: "+{-# LINE 166 "src/Data/List/Match/Private.hs" #-}+ DocTest.example+{-# LINE 166 "src/Data/List/Match/Private.hs" #-}+ (lessOrEqualLength "" undefined)+ [ExpectedLine [LineChunk "True"]]+ DocTest.printPrefix "Data.List.Match.Private:181: "+{-# LINE 181 "src/Data/List/Match/Private.hs" #-}+ DocTest.example+{-# LINE 181 "src/Data/List/Match/Private.hs" #-}+ (shorterList (shorterList (repeat 'a') (repeat 'b')) "abc")+ [ExpectedLine [LineChunk "\"abc\""]]+ DocTest.printPrefix "Data.List.Match.Private:200: "+{-# LINE 200 "src/Data/List/Match/Private.hs" #-}+ DocTest.example+{-# LINE 200 "src/Data/List/Match/Private.hs" #-}+ (List.take 3 $ shorterListEq ("abc" ++ repeat 'a') ("abcdef" ++ repeat 'b'))+ [ExpectedLine [LineChunk "\"abc\""]]
+ src/DocTest/Data/List/Reverse/Private.hs view
@@ -0,0 +1,35 @@+-- Do not edit! Automatically created with doctest-extract from src/Data/List/Reverse/Private.hs+{-# LINE 9 "src/Data/List/Reverse/Private.hs" #-}++module DocTest.Data.List.Reverse.Private where++import Data.List.Reverse.Private+import qualified Test.DocTest.Driver as DocTest++{-# LINE 10 "src/Data/List/Reverse/Private.hs" #-}+import Test.Utility (forAllPredicates)+import qualified Data.List.Reverse.StrictElement as Rev+import Prelude hiding (dropWhile, takeWhile)++test :: DocTest.T ()+test = do+ DocTest.printPrefix "Data.List.Reverse.Private:16: "+{-# LINE 16 "src/Data/List/Reverse/Private.hs" #-}+ DocTest.property+{-# LINE 16 "src/Data/List/Reverse/Private.hs" #-}+ (forAllPredicates $ \p xs -> dropWhile p xs == Rev.dropWhile p xs)+ DocTest.printPrefix "Data.List.Reverse.Private:23: "+{-# LINE 23 "src/Data/List/Reverse/Private.hs" #-}+ DocTest.property+{-# LINE 23 "src/Data/List/Reverse/Private.hs" #-}+ (forAllPredicates $ \p xs -> takeWhile0 p xs == Rev.takeWhile p xs)+ DocTest.printPrefix "Data.List.Reverse.Private:32: "+{-# LINE 32 "src/Data/List/Reverse/Private.hs" #-}+ DocTest.property+{-# LINE 32 "src/Data/List/Reverse/Private.hs" #-}+ (forAllPredicates $ \p xs -> takeWhile1 p xs == Rev.takeWhile p xs)+ DocTest.printPrefix "Data.List.Reverse.Private:46: "+{-# LINE 46 "src/Data/List/Reverse/Private.hs" #-}+ DocTest.property+{-# LINE 46 "src/Data/List/Reverse/Private.hs" #-}+ (forAllPredicates $ \p xs -> takeWhile2 p xs == Rev.takeWhile p xs)
+ src/DocTest/Data/List/Reverse/StrictElement.hs view
@@ -0,0 +1,50 @@+-- Do not edit! Automatically created with doctest-extract from src/Data/List/Reverse/StrictElement.hs+{-# LINE 15 "src/Data/List/Reverse/StrictElement.hs" #-}++module DocTest.Data.List.Reverse.StrictElement where++import Data.List.Reverse.StrictElement+import qualified Test.DocTest.Driver as DocTest++{-# LINE 16 "src/Data/List/Reverse/StrictElement.hs" #-}+import Test.Utility (forAllPredicates, defined)+import qualified Data.List.Reverse.StrictElement as Rev+import qualified Data.List.Match as Match+import qualified Data.List as List+import Data.Tuple.HT (mapPair, swap)++_suppressUnusedImportWarning :: (a -> Bool) -> [a] -> [a]+_suppressUnusedImportWarning = Data.List.Reverse.StrictElement.dropWhile++test :: DocTest.T ()+test = do+ DocTest.printPrefix "Data.List.Reverse.StrictElement:31: "+{-# LINE 31 "src/Data/List/Reverse/StrictElement.hs" #-}+ DocTest.property+{-# LINE 31 "src/Data/List/Reverse/StrictElement.hs" #-}+ (forAllPredicates $ \p xs -> Rev.dropWhile p xs == reverse (List.dropWhile p (reverse xs)))+ DocTest.printPrefix "Data.List.Reverse.StrictElement:32: "+{-# LINE 32 "src/Data/List/Reverse/StrictElement.hs" #-}+ DocTest.property+{-# LINE 32 "src/Data/List/Reverse/StrictElement.hs" #-}+ (\x xs pad -> defined $ Match.take (pad::[()]) $ Rev.dropWhile ((x::Char)/=) $ cycle $ x:xs)+ DocTest.printPrefix "Data.List.Reverse.StrictElement:41: "+{-# LINE 41 "src/Data/List/Reverse/StrictElement.hs" #-}+ DocTest.property+{-# LINE 41 "src/Data/List/Reverse/StrictElement.hs" #-}+ (forAllPredicates $ \p xs -> Rev.takeWhile p xs == reverse (List.takeWhile p (reverse xs)))+ DocTest.printPrefix "Data.List.Reverse.StrictElement:52: "+{-# LINE 52 "src/Data/List/Reverse/StrictElement.hs" #-}+ DocTest.property+{-# LINE 52 "src/Data/List/Reverse/StrictElement.hs" #-}+ (forAllPredicates $ \p xs -> Rev.span p xs == swap (mapPair (reverse, reverse) (List.span p (reverse xs))))+ DocTest.printPrefix "Data.List.Reverse.StrictElement:53: "+{-# LINE 53 "src/Data/List/Reverse/StrictElement.hs" #-}+ DocTest.property+{-# LINE 53 "src/Data/List/Reverse/StrictElement.hs" #-}+ (forAllPredicates $ \p xs -> Rev.span p xs == (Rev.dropWhile p xs, Rev.takeWhile p xs))+ DocTest.printPrefix "Data.List.Reverse.StrictElement:54: "+{-# LINE 54 "src/Data/List/Reverse/StrictElement.hs" #-}+ DocTest.property+{-# LINE 54 "src/Data/List/Reverse/StrictElement.hs" #-}+ (\x xs pad -> defined $ Match.take (pad::[()]) $ fst $ Rev.span ((x::Char)/=) $ cycle $ x:xs)
+ src/DocTest/Data/List/Reverse/StrictSpine.hs view
@@ -0,0 +1,55 @@+-- Do not edit! Automatically created with doctest-extract from src/Data/List/Reverse/StrictSpine.hs+{-# LINE 14 "src/Data/List/Reverse/StrictSpine.hs" #-}++module DocTest.Data.List.Reverse.StrictSpine where++import Data.List.Reverse.StrictSpine+import qualified Test.DocTest.Driver as DocTest++{-# LINE 15 "src/Data/List/Reverse/StrictSpine.hs" #-}+import Test.Utility (forAllPredicates, defined)+import qualified Data.List.Reverse.StrictSpine as Rev+import qualified Data.List.Match as Match+import qualified Data.List as List+import Data.Tuple.HT (mapFst, mapPair, swap)++_suppressUnusedImportWarning :: (a -> Bool) -> [a] -> [a]+_suppressUnusedImportWarning = Data.List.Reverse.StrictSpine.dropWhile++test :: DocTest.T ()+test = do+ DocTest.printPrefix "Data.List.Reverse.StrictSpine:26: "+{-# LINE 26 "src/Data/List/Reverse/StrictSpine.hs" #-}+ DocTest.property+{-# LINE 26 "src/Data/List/Reverse/StrictSpine.hs" #-}+ (forAllPredicates $ \p xs -> Rev.dropWhile p xs == reverse (List.dropWhile p (reverse xs)))+ DocTest.printPrefix "Data.List.Reverse.StrictSpine:27: "+{-# LINE 27 "src/Data/List/Reverse/StrictSpine.hs" #-}+ DocTest.property+{-# LINE 27 "src/Data/List/Reverse/StrictSpine.hs" #-}+ (\x xs pad -> defined $ length $ Rev.dropWhile ((x::Char)/=) $ Match.replicate (pad::[()]) undefined ++ x:xs)+ DocTest.printPrefix "Data.List.Reverse.StrictSpine:34: "+{-# LINE 34 "src/Data/List/Reverse/StrictSpine.hs" #-}+ DocTest.property+{-# LINE 34 "src/Data/List/Reverse/StrictSpine.hs" #-}+ (forAllPredicates $ \p xs -> Rev.takeWhile p xs == reverse (List.takeWhile p (reverse xs)))+ DocTest.printPrefix "Data.List.Reverse.StrictSpine:35: "+{-# LINE 35 "src/Data/List/Reverse/StrictSpine.hs" #-}+ DocTest.property+{-# LINE 35 "src/Data/List/Reverse/StrictSpine.hs" #-}+ (\x xs pad -> defined $ Rev.takeWhile ((x::Char)/=) $ Match.replicate (pad::[()]) undefined ++ x:xs)+ DocTest.printPrefix "Data.List.Reverse.StrictSpine:46: "+{-# LINE 46 "src/Data/List/Reverse/StrictSpine.hs" #-}+ DocTest.property+{-# LINE 46 "src/Data/List/Reverse/StrictSpine.hs" #-}+ (forAllPredicates $ \p xs -> Rev.span p xs == swap (mapPair (reverse, reverse) (List.span p (reverse xs))))+ DocTest.printPrefix "Data.List.Reverse.StrictSpine:47: "+{-# LINE 47 "src/Data/List/Reverse/StrictSpine.hs" #-}+ DocTest.property+{-# LINE 47 "src/Data/List/Reverse/StrictSpine.hs" #-}+ (forAllPredicates $ \p xs -> Rev.span p xs == (Rev.dropWhile p xs, Rev.takeWhile p xs))+ DocTest.printPrefix "Data.List.Reverse.StrictSpine:48: "+{-# LINE 48 "src/Data/List/Reverse/StrictSpine.hs" #-}+ DocTest.property+{-# LINE 48 "src/Data/List/Reverse/StrictSpine.hs" #-}+ (\x xs pad -> defined $ mapFst length $ Rev.span ((x::Char)/=) $ Match.replicate (pad::[()]) undefined ++ x:xs)
+ src/DocTest/Data/Maybe/HT.hs view
@@ -0,0 +1,18 @@+-- Do not edit! Automatically created with doctest-extract from src/Data/Maybe/HT.hs+{-# LINE 6 "src/Data/Maybe/HT.hs" #-}++module DocTest.Data.Maybe.HT where++import Data.Maybe.HT+import qualified Test.DocTest.Driver as DocTest++{-# LINE 7 "src/Data/Maybe/HT.hs" #-}+import Control.Monad (guard)++test :: DocTest.T ()+test = do+ DocTest.printPrefix "Data.Maybe.HT:15: "+{-# LINE 15 "src/Data/Maybe/HT.hs" #-}+ DocTest.property+{-# LINE 15 "src/Data/Maybe/HT.hs" #-}+ (\b x -> (guard b >> x) == (toMaybe b =<< (x::Maybe Char)))
+ src/DocTest/Data/Monoid/HT.hs view
@@ -0,0 +1,36 @@+-- Do not edit! Automatically created with doctest-extract from src/Data/Monoid/HT.hs+{-# LINE 9 "src/Data/Monoid/HT.hs" #-}++module DocTest.Data.Monoid.HT where++import Data.Monoid.HT+import qualified Test.DocTest.Driver as DocTest++{-# LINE 10 "src/Data/Monoid/HT.hs" #-}+import qualified Test.QuickCheck as QC+import Control.Monad (mfilter)+import Data.Function.HT (powerAssociative)+import Data.Monoid (mconcat, mappend, mempty)++test :: DocTest.T ()+test = do+ DocTest.printPrefix "Data.Monoid.HT:34: "+{-# LINE 34 "src/Data/Monoid/HT.hs" #-}+ DocTest.property+{-# LINE 34 "src/Data/Monoid/HT.hs" #-}+ (\b m -> when b m == mfilter (const b) (m::Maybe Ordering))+ DocTest.printPrefix "Data.Monoid.HT:35: "+{-# LINE 35 "src/Data/Monoid/HT.hs" #-}+ DocTest.property+{-# LINE 35 "src/Data/Monoid/HT.hs" #-}+ (\b m -> when b m == mfilter (const b) (m::String))+ DocTest.printPrefix "Data.Monoid.HT:41: "+{-# LINE 41 "src/Data/Monoid/HT.hs" #-}+ DocTest.property+{-# LINE 41 "src/Data/Monoid/HT.hs" #-}+ (QC.forAll (QC.choose (0,20)) $ \k xs -> power (fromIntegral k) xs == mconcat (replicate k (xs::String)))+ DocTest.printPrefix "Data.Monoid.HT:46: "+{-# LINE 46 "src/Data/Monoid/HT.hs" #-}+ DocTest.property+{-# LINE 46 "src/Data/Monoid/HT.hs" #-}+ (QC.forAll (QC.choose (0,20)) $ \k xs -> power k xs == powerAssociative mappend mempty (xs::String) k)
src/Test.hs view
@@ -1,25 +1,26 @@+-- Do not edit! Automatically created with doctest-extract. module Main where -import qualified Test.Data.List.Reverse.StrictElement as RevElem-import qualified Test.Data.List.Reverse.StrictSpine as RevSpine-import qualified Test.Data.List as ListHT-import qualified Test.Data.ListMatch as ListMatch-import qualified Test.Data.Maybe as MaybeHT-import qualified Test.Data.Function as FunctionHT-+import qualified DocTest.Data.List.Reverse.StrictSpine+import qualified DocTest.Data.List.Reverse.StrictElement+import qualified DocTest.Data.List.Reverse.Private+import qualified DocTest.Data.List.Match.Private+import qualified DocTest.Data.List.HT.Private+import qualified DocTest.Data.Maybe.HT+import qualified DocTest.Data.Bool.HT.Private+import qualified DocTest.Data.Monoid.HT+import qualified DocTest.Data.Function.HT.Private -prefix :: String -> [(String, IO ())] -> [(String, IO ())]-prefix msg =- map (\(str,test) -> (msg ++ "." ++ str, test))+import qualified Test.DocTest.Driver as DocTest main :: IO ()-main =- mapM_ (\(msg,io) -> putStr (msg++": ") >> io) $- concat $- prefix "ReverseSpine" RevSpine.tests :- prefix "ReverseElem" RevElem.tests :- prefix "List" ListHT.tests :- prefix "ListMatch" ListMatch.tests :- prefix "Maybe" MaybeHT.tests :- prefix "Function" FunctionHT.tests :- []+main = DocTest.run $ do+ DocTest.Data.List.Reverse.StrictSpine.test+ DocTest.Data.List.Reverse.StrictElement.test+ DocTest.Data.List.Reverse.Private.test+ DocTest.Data.List.Match.Private.test+ DocTest.Data.List.HT.Private.test+ DocTest.Data.Maybe.HT.test+ DocTest.Data.Bool.HT.Private.test+ DocTest.Data.Monoid.HT.test+ DocTest.Data.Function.HT.Private.test
− src/Test/Data/Function.hs
@@ -1,27 +0,0 @@-module Test.Data.Function where--import qualified Data.Function.HT.Private as FuncHT--import Test.QuickCheck (NonNegative(NonNegative), quickCheck)---nest :: (Eq a) => NonNegative Int -> (a -> a) -> a -> Bool-nest (NonNegative n) f x =- FuncHT.nest n f x == FuncHT.nest1 n f x &&- FuncHT.nest n f x == FuncHT.nest2 n f x--powerAssociative :: Eq a =>- (a -> a -> a) -> a -> a -> NonNegative Integer -> Bool-powerAssociative op a0 a (NonNegative n) =- FuncHT.powerAssociative op a0 a n == FuncHT.powerAssociativeList op a0 a n &&- FuncHT.powerAssociative op a0 a n == FuncHT.powerAssociativeNaive op a0 a n---tests :: [(String, IO ())]-tests =- ("nest",- quickCheck (flip nest succ :: NonNegative Int -> Integer -> Bool)) :- ("powerAssociative",- quickCheck (powerAssociative (+) ::- Integer -> Integer -> NonNegative Integer -> Bool)) :- []
− src/Test/Data/List.hs
@@ -1,208 +0,0 @@-module Test.Data.List where--import qualified Data.List.Reverse.StrictElement as Rev-import qualified Data.List.HT.Private as ListHT-import qualified Data.List as List-import Data.Maybe.HT (toMaybe, )-import Control.Monad (liftM2, )--import qualified Test.QuickCheck.Modifiers as Mod-import qualified Test.QuickCheck as QC-import Test.Utility (equalLists, equalInfLists, )-import Test.QuickCheck (Arbitrary, Testable, Property, quickCheck, )--import Prelude hiding (iterate, )----takeWhileRev0 :: (Eq a) => (a -> Bool) -> [a] -> Bool-takeWhileRev0 p xs =- ListHT.takeWhileRev0 p xs == Rev.takeWhile p xs--takeWhileRev1 :: (Eq a) => (a -> Bool) -> [a] -> Bool-takeWhileRev1 p xs =- ListHT.takeWhileRev1 p xs == Rev.takeWhile p xs--takeWhileRev2 :: (Eq a) => (a -> Bool) -> [a] -> Bool-takeWhileRev2 p xs =- ListHT.takeWhileRev2 p xs == Rev.takeWhile p xs--dropWhileRev :: (Eq a) => (a -> Bool) -> [a] -> Bool-dropWhileRev p xs =- ListHT.dropWhileRev p xs == Rev.dropWhile p xs---takeRev :: (Eq a) => Int -> [a] -> Bool-takeRev n xs =- ListHT.takeRev n xs == reverse (take n (reverse xs))--dropRev :: (Eq a) => Int -> [a] -> Bool-dropRev n xs =- ListHT.dropRev n xs == reverse (drop n (reverse xs))--splitAtRev :: (Eq a) => Int -> [a] -> Bool-splitAtRev n xs =- xs == uncurry (++) (ListHT.splitAtRev n xs)---breakAfterAppend :: (Eq a) => (a -> Bool) -> [a] -> Bool-breakAfterAppend p xs =- uncurry (++) (ListHT.breakAfter p xs) == xs--breakAfter0 :: (Eq a) => (a -> Bool) -> [a] -> Bool-breakAfter0 p xs =- ListHT.breakAfterRec p xs == ListHT.breakAfterFoldr p xs--breakAfter1 :: (Eq a) => (a -> Bool) -> [a] -> Bool-breakAfter1 p xs =- ListHT.breakAfterRec p xs == ListHT.breakAfterBreak p xs--breakAfter2 :: (Eq a) => (a -> Bool) -> [a] -> Bool-breakAfter2 p xs =- ListHT.breakAfterRec p xs == ListHT.breakAfterTakeUntil p xs--breakAfterUntil :: (Eq a) => (a -> Bool) -> [a] -> Bool-breakAfterUntil p xs =- ListHT.takeUntil p xs == fst (ListHT.breakAfter p xs)---geMaybe :: Float -> Float -> Maybe Integer-geMaybe x y = toMaybe (x < y) (round y)--dropWhileNothing :: Float -> [Float] -> Bool-dropWhileNothing x xs =- ListHT.dropWhileNothing (geMaybe x) xs- ==- ListHT.dropWhileNothingRec (geMaybe x) xs--dropWhileNothingBreakJust :: Float -> [Float] -> Bool-dropWhileNothingBreakJust x xs =- snd (ListHT.breakJust (geMaybe x) xs)- ==- ListHT.dropWhileNothing (geMaybe x) xs--breakJustRemoveEach :: Float -> [Float] -> Bool-breakJustRemoveEach x xs =- ListHT.breakJust (geMaybe x) xs == ListHT.breakJustRemoveEach (geMaybe x) xs--breakJustPartial :: Float -> [Float] -> Bool-breakJustPartial x xs =- ListHT.breakJust (geMaybe x) xs == ListHT.breakJustPartial (geMaybe x) xs---sieve :: Eq a => Mod.Positive Int -> [a] -> Bool-sieve (Mod.Positive n) x =- equalLists $- (ListHT.sieve n x) :- (ListHT.sieve' n x) :- (ListHT.sieve'' n x) :- (ListHT.sieve''' n x) :- []---sliceHorizontal :: Eq a => [a] -> Property-sliceHorizontal x =- QC.forAll (QC.choose (1,1000)) $ \n ->- ListHT.sliceHorizontal n x == ListHT.sliceHorizontal' n x---sliceVertical :: Eq a => Mod.Positive Int -> [a] -> Bool-sliceVertical (Mod.Positive n) x =- ListHT.sliceVertical n x == ListHT.sliceVertical' n x--slice :: Eq a => Mod.NonEmptyList a -> Property-slice (Mod.NonEmpty x) =- QC.forAll (QC.choose (1, length x)) $ \n ->- -- problems: ListHT.sliceHorizontal 4 [] == [[],[],[],[]]- ListHT.sliceHorizontal n x == List.transpose (ListHT.sliceVertical n x) &&- ListHT.sliceVertical n x == List.transpose (ListHT.sliceHorizontal n x)-----shear :: Eq a => [[a]] -> Bool-shear xs =- ListHT.shearTranspose xs == map reverse (ListHT.shear xs)----outerProduct :: (Eq a, Eq b) => [a] -> [b] -> Bool-outerProduct xs ys =- concat (ListHT.outerProduct (,) xs ys) == liftM2 (,) xs ys---lengthAtLeast :: Int -> [a] -> Bool-lengthAtLeast n xs =- ListHT.lengthAtLeast n xs == (length xs >= n)--lengthAtMost :: Int -> [a] -> Bool-lengthAtMost n xs =- ListHT.lengthAtMost n xs == (length xs <= n)--lengthAtMost0 :: Int -> [a] -> Bool-lengthAtMost0 n xs =- ListHT.lengthAtMost0 n xs == (length xs <= n)---iterate :: Eq a => (a -> a -> a) -> a -> Bool-iterate op a =- let xs = List.iterate (op a) a- ys = ListHT.iterateAssociative op a- zs = ListHT.iterateLeaky op a- in equalInfLists 1000 [xs, ys, zs]---mapAdjacent :: (Num a, Eq a) => a -> [a] -> Bool-mapAdjacent x xs =- ListHT.mapAdjacent subtract (scanl (+) x xs) == xs--mapAdjacentPointfree :: (Num a, Eq a) => [a] -> Bool-mapAdjacentPointfree xs =- ListHT.mapAdjacent (+) xs == ListHT.mapAdjacentPointfree (+) xs---simple ::- (Show int, Arbitrary int, Testable test) =>- (int -> [Integer] -> test) -> IO ()-simple = quickCheck--elemCheck ::- (Testable test) =>- (Float -> [Float] -> test) -> IO ()-elemCheck = quickCheck---tests :: [(String, IO ())]-tests =- ("takeWhileRev0", elemCheck (\a -> takeWhileRev0 (a>=))) :- ("takeWhileRev1", elemCheck (\a -> takeWhileRev1 (a>=))) :- ("takeWhileRev2", elemCheck (\a -> takeWhileRev2 (a>=))) :- ("dropWhileRev", elemCheck (\a -> dropWhileRev (a>=))) :- ("takeRev", simple takeRev) :- ("dropRev", simple dropRev) :- ("splitAtRev", simple splitAtRev) :- ("breakAfterAppend", elemCheck (\a -> breakAfterAppend (a>=))) :- ("breakAfter0", elemCheck (\a -> breakAfter0 (a>=))) :- ("breakAfter1", elemCheck (\a -> breakAfter1 (a>=))) :- ("breakAfter2", elemCheck (\a -> breakAfter2 (a>=))) :- ("breakAfterUntil", elemCheck (\a -> breakAfterUntil (a>=))) :- ("dropWhileNothing", elemCheck dropWhileNothing) :- ("dropWhileNothingBreakJust",- elemCheck dropWhileNothingBreakJust) :- ("breakJustRemoveEach",- elemCheck breakJustRemoveEach) :- ("breakJustPartial", elemCheck breakJustPartial) :- ("sieve", simple sieve) :- ("sliceHorizontal", quickCheck (sliceHorizontal :: String -> Property)) :- ("sliceVertical", simple sliceVertical) :- ("slice", quickCheck (slice :: Mod.NonEmptyList Char -> Property)) :- ("shear", quickCheck (shear :: [[Integer]] -> Bool)) :- ("outerProduct", quickCheck (outerProduct :: [Integer] -> [Int] -> Bool)) :- ("lengthAtLeast", simple lengthAtLeast) :- ("lengthAtMost", simple lengthAtMost) :- ("lengthAtMost0", simple lengthAtMost0) :- ("iterate", quickCheck (iterate (+) :: Integer -> Bool)) :- ("mapAdjacent", quickCheck (mapAdjacent :: Integer -> [Integer] -> Bool)) :- ("mapAdjacentPointfree",- quickCheck (mapAdjacentPointfree :: [Integer] -> Bool)) :- []
− src/Test/Data/List/Reverse/StrictElement.hs
@@ -1,53 +0,0 @@-module Test.Data.List.Reverse.StrictElement where--import qualified Data.List.Reverse.StrictElement as Rev-import qualified Data.List as List-import Data.Tuple.HT (mapPair, swap, )--import Test.QuickCheck (Testable, quickCheck, )--import Prelude hiding (takeWhile, dropWhile, span, )---takeWhile :: (Ord a) => (a -> Bool) -> [a] -> Bool-takeWhile p xs =- Rev.takeWhile p xs == reverse (List.takeWhile p (reverse xs))--dropWhile :: (Ord a) => (a -> Bool) -> [a] -> Bool-dropWhile p xs =- Rev.dropWhile p xs == reverse (List.dropWhile p (reverse xs))--span :: (Ord a) => (a -> Bool) -> [a] -> Bool-span p xs =- Rev.span p xs == swap (mapPair (reverse, reverse) (List.span p (reverse xs)))--spanTakeDrop :: (Ord a) => (a -> Bool) -> [a] -> Bool-spanTakeDrop p xs =- Rev.span p xs == (Rev.dropWhile p xs, Rev.takeWhile p xs)--dropWhileInf :: (Ord a) => a -> [a] -> Bool-dropWhileInf x xs =- let ys = List.take 1000 $ Rev.dropWhile (x/=) $ cycle $ x:xs- in ys==ys--spanInf :: (Ord a) => a -> [a] -> Bool-spanInf x xs =- let ys = List.take 1000 $ fst $ Rev.span (x/=) $ cycle $ x:xs- in ys==ys---simple ::- (Testable test) =>- (Float -> [Float] -> test) -> IO ()-simple = quickCheck---tests :: [(String, IO ())]-tests =- ("takeWhile", simple (\a -> takeWhile (a>=))) :- ("dropWhile", simple (\a -> dropWhile (a>=))) :- ("span", simple (\a -> span (a>=))) :- ("spanTakeDrop", simple (\a -> spanTakeDrop (a>=))) :- ("dropWhileInf", simple dropWhileInf) :- ("spanInf", simple spanInf) :- []
− src/Test/Data/List/Reverse/StrictSpine.hs
@@ -1,62 +0,0 @@-module Test.Data.List.Reverse.StrictSpine where--import qualified Data.List.Reverse.StrictSpine as Rev-import qualified Data.List.Match as Match-import qualified Data.List as List-import Data.Tuple.HT (mapFst, mapPair, swap, )--import Test.QuickCheck (Testable, quickCheck, )--import Prelude hiding (takeWhile, dropWhile, span, )---takeWhile :: (Ord a) => (a -> Bool) -> [a] -> Bool-takeWhile p xs =- Rev.takeWhile p xs == reverse (List.takeWhile p (reverse xs))--dropWhile :: (Ord a) => (a -> Bool) -> [a] -> Bool-dropWhile p xs =- Rev.dropWhile p xs == reverse (List.dropWhile p (reverse xs))--span :: (Ord a) => (a -> Bool) -> [a] -> Bool-span p xs =- Rev.span p xs == swap (mapPair (reverse, reverse) (List.span p (reverse xs)))--spanTakeDrop :: (Ord a) => (a -> Bool) -> [a] -> Bool-spanTakeDrop p xs =- Rev.span p xs == (Rev.dropWhile p xs, Rev.takeWhile p xs)--takeWhileBottom :: (Ord a) => a -> [a] -> [a] -> Bool-takeWhileBottom x xs pad =- let ys = Rev.takeWhile (x/=) $ Match.replicate pad undefined ++ x:xs- in ys==ys--dropWhileBottom :: (Ord a) => a -> [a] -> [a] -> Bool-dropWhileBottom x xs pad =- let n = length $ Rev.dropWhile (x/=) $ Match.replicate pad undefined ++ x:xs- in n==n--spanBottom :: (Ord a) => a -> [a] -> [a] -> Bool-spanBottom x xs pad =- let (n,ys) =- mapFst length $ Rev.span (x/=) $- Match.replicate pad undefined ++ x:xs- in n==n && ys==ys---simple ::- (Testable test) =>- (Float -> [Float] -> test) -> IO ()-simple = quickCheck---tests :: [(String, IO ())]-tests =- ("takeWhile", simple (\a -> takeWhile (a>=))) :- ("dropWhile", simple (\a -> dropWhile (a>=))) :- ("span", simple (\a -> span (a>=))) :- ("spanTakeDrop", simple (\a -> spanTakeDrop (a>=))) :- ("takeWhileBottom", simple takeWhileBottom) :- ("dropWhileBottom", simple dropWhileBottom) :- ("spanBottom", simple spanBottom) :- []
− src/Test/Data/ListMatch.hs
@@ -1,77 +0,0 @@-module Test.Data.ListMatch where--import qualified Data.List.Match.Private as Match-import qualified Data.List as List--import Test.Utility (equalLists, )-import Test.QuickCheck (Testable, quickCheck, )--import Prelude hiding (iterate, take, drop, splitAt, )----laxTail :: (Eq a) => [a] -> Bool-laxTail xs =- Match.laxTail xs == Match.laxTail0 xs--take :: (Eq a) => [b] -> [a] -> Bool-take xs ys =- Match.take xs ys == List.take (length xs) ys--drop :: (Eq a) => [b] -> [a] -> Bool-drop xs ys =- Match.drop xs ys == List.drop (length xs) ys--dropAlt :: (Eq a) => [b] -> [a] -> Bool-dropAlt xs ys =- equalLists $- Match.drop xs ys :- Match.drop0 xs ys :- Match.drop1 xs ys :- Match.drop2 xs ys :- Match.dropRec xs ys :- []--takeDrop :: (Eq a) => [b] -> [a] -> Bool-takeDrop xs ys =- Match.take xs ys ++ Match.drop xs ys == ys--splitAt :: (Eq a) => [b] -> [a] -> Bool-splitAt xs ys =- (Match.take xs ys, Match.drop xs ys) == Match.splitAt xs ys---takeRev :: (Eq a) => [b] -> [a] -> Bool-takeRev xs ys =- Match.takeRev xs ys == reverse (Match.take xs (reverse ys))--dropRev :: (Eq a) => [b] -> [a] -> Bool-dropRev xs ys =- Match.dropRev xs ys == reverse (Match.drop xs (reverse ys))---compareLength :: [a] -> [b] -> Bool-compareLength xs ys =- Match.compareLength xs ys == Match.compareLength0 xs ys &&- Match.compareLength xs ys == Match.compareLength1 xs ys---test1 :: Testable test => ([Int] -> test) -> IO ()-test1 = quickCheck--test2 :: Testable test => ([Int] -> [Integer] -> test) -> IO ()-test2 = quickCheck---tests :: [(String, IO ())]-tests =- ("laxTail", test1 laxTail) :- ("take", test2 take) :- ("drop", test2 drop) :- ("dropAlt", test2 dropAlt) :- ("takeDrop", test2 takeDrop) :- ("splitAt", test2 splitAt) :- ("takeRev", test2 takeRev) :- ("dropRev", test2 dropRev) :- ("compareLength", test2 compareLength) :- []
− src/Test/Data/Maybe.hs
@@ -1,17 +0,0 @@-module Test.Data.Maybe where--import Control.Monad (guard, )-import Data.Maybe.HT (toMaybe, )--import Test.QuickCheck (quickCheck, )---toMaybeGuard :: Eq a => Bool -> Maybe a -> Bool-toMaybeGuard b x =- (guard b >> x) == (toMaybe b =<< x)---tests :: [(String, IO ())]-tests =- ("toMaybeGuard", quickCheck (\b x -> toMaybeGuard b (x::Maybe Int))) :- []
src/Test/Utility.hs view
@@ -1,6 +1,8 @@ -- cf. Test.NumericPrelude.Utility module Test.Utility where +import qualified Test.QuickCheck as QC+ import Data.List.HT (mapAdjacent, ) import qualified Data.List as List @@ -14,3 +16,11 @@ equalInfLists :: Eq a => Int -> [[a]] -> Bool equalInfLists n xs = equalLists (map (take n) xs)+++forAllPredicates ::+ (QC.Testable test) => ((Char -> Bool) -> test) -> QC.Property+forAllPredicates prop = QC.property $ \x -> prop (x<=)++defined :: (Eq a) => a -> Bool+defined a = a==a
+ test-module.list view
@@ -0,0 +1,9 @@+Data.List.Reverse.StrictSpine+Data.List.Reverse.StrictElement+Data.List.Reverse.Private+Data.List.Match.Private+Data.List.HT.Private+Data.Maybe.HT+Data.Bool.HT.Private+Data.Monoid.HT+Data.Function.HT.Private
utility-ht.cabal view
@@ -1,6 +1,7 @@+Cabal-Version: 2.2 Name: utility-ht-Version: 0.0.15-License: BSD3+Version: 0.0.16+License: BSD-3-Clause License-File: LICENSE Author: Henning Thielemann <haskell@henning-thielemann.de> Maintainer: Henning Thielemann <haskell@henning-thielemann.de>@@ -22,20 +23,14 @@ However, further splitting the base package might invalidate this statement. . Alternative packages: @Useful@, @MissingH@-Tested-With: GHC==6.8.2, GHC==6.10.4, GHC==6.12.3 Tested-With: GHC==7.0.2, GHC==7.2.2, GHC==7.4.1, GHC==7.8.2-Cabal-Version: >=1.10+Tested-With: GHC==8.6.5 Build-Type: Simple Stability: Stable --- workaround for Cabal-1.10 Extra-Source-Files:- src/Test/Data/Maybe.hs- src/Test/Data/ListMatch.hs- src/Test/Data/Function.hs- src/Test/Data/List.hs- src/Test/Utility.hs- src/Test.hs+ Makefile+ test-module.list Source-Repository head type: darcs@@ -44,7 +39,7 @@ Source-Repository this type: darcs location: http://code.haskell.org/~thielema/utility/- tag: 0.0.15+ tag: 0.0.16 Library Build-Depends:@@ -84,6 +79,7 @@ Data.List.HT.Private Data.List.Key.Private Data.List.Match.Private+ Data.List.Reverse.Private Data.Function.HT.Private Data.Record.HT.Private Data.Tuple.Example@@ -93,16 +89,21 @@ Type: exitcode-stdio-1.0 Build-Depends: QuickCheck >=1.1 && <3,+ doctest-exitcode-stdio >=0.0 && <0.1,+ doctest-lib >=0.1 && <0.1.1, base >=3 && <5 Default-Language: Haskell98 Main-Is: Test.hs GHC-Options: -Wall Hs-source-dirs: src Other-Modules:- Test.Data.List- Test.Data.ListMatch- Test.Data.List.Reverse.StrictElement- Test.Data.List.Reverse.StrictSpine- Test.Data.Maybe- Test.Data.Function Test.Utility+ DocTest.Data.List.Reverse.StrictElement+ DocTest.Data.List.Reverse.StrictSpine+ DocTest.Data.List.Reverse.Private+ DocTest.Data.List.Match.Private+ DocTest.Data.List.HT.Private+ DocTest.Data.Monoid.HT+ DocTest.Data.Maybe.HT+ DocTest.Data.Bool.HT.Private+ DocTest.Data.Function.HT.Private