strict-list 0.1 → 0.1.0.1
raw patch · 3 files changed
+25/−6 lines, 3 files
Files
- library/StrictList.hs +7/−2
- strict-list.cabal +1/−1
- test/Main.hs +17/−3
library/StrictList.hs view
@@ -11,7 +11,10 @@ One useful rule of thumb would be that whenever you see that a function has a reversed counterpart, that counterpart is faster and hence if you don't care about the order or-intend to revert the list further down the line, you should give preference to that counterpart.+intend to reverse the list further down the line, you should give preference to that counterpart.++The typical `toList` and `fromList` conversions are provided by means of+the `Foldable` and `IsList` instances. -} module StrictList where @@ -29,7 +32,9 @@ toList = foldr (:) [] instance Semigroup (List a) where- (<>) = prependReversed . reverse+ (<>) a b = case b of+ Nil -> a+ _ -> prependReversed (reverse a) b instance Monoid (List a) where mempty = Nil
strict-list.cabal view
@@ -1,5 +1,5 @@ name: strict-list-version: 0.1+version: 0.1.0.1 synopsis: Strict linked list description: Implementation of strict linked list with care taken about stack.
test/Main.hs view
@@ -1,6 +1,6 @@ module Main where -import Prelude hiding (reverse, toList, List, filter, take, drop, takeWhile, dropWhile, head, last, tail, init)+import Prelude hiding (choose, reverse, toList, List, filter, take, drop, takeWhile, dropWhile, head, last, tail, init) import GHC.Exts as Exports (IsList(..)) import Test.QuickCheck.Instances import Test.Tasty@@ -100,6 +100,16 @@ , testProperty ">>=" $ forAll ((,) <$> strictAndLazyKleisliGen <*> strictAndLazyListGen) $ \ ((strictK, lazyK), (strict, lazy)) -> toList (strict >>= strictK) === (lazy >>= lazyK)+ ,+ testProperty "foldl'" $ forAll strictAndLazyListGen $ \ (strict, lazy) ->+ foldl' (flip (:)) [] strict === foldl' (flip (:)) [] lazy+ ,+ testProperty "foldr" $ forAll strictAndLazyListGen $ \ (strict, lazy) ->+ foldr (:) [] strict === foldr (:) [] lazy+ ,+ testProperty "traverse" $ forAll strictAndLazyListGen $ \ (strict, lazy) -> let+ fn x = if mod x 2 == 0 then Right x else Left x+ in fmap toList (traverse fn strict) === traverse fn lazy ] where lazyListGen = arbitrary @[Word8]@@ -111,11 +121,15 @@ x <- arbitrary @Word8 return (op x) strictAndLazyKleisliGen = do- lazy <- lazyListGen+ lazy <- sizedListGen 10 let- lazyK = \ x -> join (replicate (fromIntegral x) lazy)+ lazyK x = fmap (+ x) lazy strictK = foldr Cons Nil . lazyK in return (strictK, lazyK)+ sizedListGen maxSize = do+ length <- choose (0, maxSize)+ replicateM length (arbitrary @Word8)+ -- * Workarounds to satisfy QuickCheck's requirements, -- when we need to generate a predicate.