deferred-folds 0.9.18.3 → 0.9.18.4
raw patch · 9 files changed
+168/−101 lines, 9 filesdep −QuickCheckdep −tasty-hunitdep ~primitive
Dependencies removed: QuickCheck, tasty-hunit
Dependency ranges changed: primitive
Files
- deferred-folds.cabal +118/−43
- library/DeferredFolds/Defs/Unfoldl.hs +5/−4
- library/DeferredFolds/Defs/UnfoldlM.hs +23/−21
- library/DeferredFolds/Defs/Unfoldr.hs +19/−17
- library/DeferredFolds/Defs/UnfoldrM.hs +1/−1
- library/DeferredFolds/Prelude.hs +0/−1
- library/DeferredFolds/Types.hs +0/−2
- library/DeferredFolds/Util/TextArray.hs +0/−3
- test/Main.hs +2/−9
deferred-folds.cabal view
@@ -1,67 +1,142 @@ cabal-version: 3.0--name: deferred-folds-version: 0.9.18.3-category: Folding-synopsis: Abstractions over deferred folds+name: deferred-folds+version: 0.9.18.4+category: Folding+synopsis: Abstractions over deferred folds description: This library is in an experimental state. Users should be prepared for frequent updates.-stability: Experimental-homepage: https://github.com/metrix-ai/deferred-folds-bug-reports: https://github.com/metrix-ai/deferred-folds/issues-author: Nikita Volkov <nikita.y.volkov@mail.ru>-maintainer: Nikita Volkov <nikita.y.volkov@mail.ru>-copyright: (c) 2018, Metrix.AI-license: MIT-license-file: LICENSE-build-type: Simple +stability: Experimental+homepage: https://github.com/metrix-ai/deferred-folds+bug-reports: https://github.com/metrix-ai/deferred-folds/issues+author: Nikita Volkov <nikita.y.volkov@mail.ru>+maintainer: Nikita Volkov <nikita.y.volkov@mail.ru>+copyright: (c) 2018, Metrix.AI+license: MIT+license-file: LICENSE+build-type: Simple+ source-repository head- type: git+ type: git location: git://github.com/metrix-ai/deferred-folds.git library- hs-source-dirs: library- default-extensions: Arrows, BangPatterns, ConstraintKinds, DataKinds, DefaultSignatures, DeriveDataTypeable, DeriveFoldable, DeriveFunctor, DeriveGeneric, DeriveTraversable, EmptyDataDecls, FlexibleContexts, FlexibleInstances, FunctionalDependencies, GADTs, GeneralizedNewtypeDeriving, LambdaCase, LiberalTypeSynonyms, MagicHash, MultiParamTypeClasses, MultiWayIf, NoImplicitPrelude, NoMonomorphismRestriction, OverloadedStrings, PatternGuards, PatternSynonyms, ParallelListComp, QuasiQuotes, RankNTypes, RecordWildCards, ScopedTypeVariables, StandaloneDeriving, TemplateHaskell, TupleSections, TypeFamilies, TypeOperators, UnboxedTuples- default-language: Haskell2010+ hs-source-dirs: library+ default-extensions:+ NoImplicitPrelude+ NoMonomorphismRestriction+ Arrows+ BangPatterns+ ConstraintKinds+ DataKinds+ DefaultSignatures+ DeriveDataTypeable+ DeriveFoldable+ DeriveFunctor+ DeriveGeneric+ DeriveTraversable+ EmptyDataDecls+ FlexibleContexts+ FlexibleInstances+ FunctionalDependencies+ GADTs+ GeneralizedNewtypeDeriving+ LambdaCase+ LiberalTypeSynonyms+ MagicHash+ MultiParamTypeClasses+ MultiWayIf+ OverloadedStrings+ ParallelListComp+ PatternGuards+ PatternSynonyms+ QuasiQuotes+ RankNTypes+ RecordWildCards+ ScopedTypeVariables+ StandaloneDeriving+ TemplateHaskell+ TupleSections+ TypeFamilies+ TypeOperators+ UnboxedTuples++ default-language: Haskell2010 exposed-modules: DeferredFolds.Unfoldl DeferredFolds.UnfoldlM DeferredFolds.Unfoldr+ other-modules:- DeferredFolds.Types- DeferredFolds.UnfoldrM DeferredFolds.Defs.Unfoldl DeferredFolds.Defs.UnfoldlM DeferredFolds.Defs.Unfoldr DeferredFolds.Defs.UnfoldrM DeferredFolds.Prelude+ DeferredFolds.Types+ DeferredFolds.UnfoldrM DeferredFolds.Util.TextArray+ build-depends:- base >=4.9 && <5,- bytestring >=0.10 && <0.12,- containers >=0.5 && <0.7,- foldl >=1 && <2,- hashable >=1 && <2,- primitive >=0.6.4 && <0.9,- text >=1.2 && <1.3 || >=2.0 && <2.1,- transformers >=0.5 && <0.7,- unordered-containers >=0.2 && <0.3,- vector >=0.12 && <0.14,+ , base >=4.9 && <5+ , bytestring >=0.10 && <0.12+ , containers >=0.5 && <0.7+ , foldl >=1 && <2+ , hashable >=1 && <2+ , primitive >=0.6.4 && <0.10+ , text >=1.2 && <1.3 || >=2.0 && <2.1+ , transformers >=0.5 && <0.7+ , unordered-containers >=0.2 && <0.3+ , vector >=0.12 && <0.14 test-suite test- type: exitcode-stdio-1.0- hs-source-dirs: test- default-extensions: Arrows, BangPatterns, ConstraintKinds, DataKinds, DefaultSignatures, DeriveDataTypeable, DeriveFoldable, DeriveFunctor, DeriveGeneric, DeriveTraversable, EmptyDataDecls, FlexibleContexts, FlexibleInstances, FunctionalDependencies, GADTs, GeneralizedNewtypeDeriving, LambdaCase, LiberalTypeSynonyms, MagicHash, MultiParamTypeClasses, MultiWayIf, NoImplicitPrelude, NoMonomorphismRestriction, OverloadedStrings, PatternGuards, PatternSynonyms, ParallelListComp, QuasiQuotes, RankNTypes, RecordWildCards, ScopedTypeVariables, StandaloneDeriving, TemplateHaskell, TupleSections, TypeFamilies, TypeOperators, UnboxedTuples- default-language: Haskell2010- main-is:- Main.hs+ type: exitcode-stdio-1.0+ hs-source-dirs: test+ default-extensions:+ NoImplicitPrelude+ NoMonomorphismRestriction+ Arrows+ BangPatterns+ ConstraintKinds+ DataKinds+ DefaultSignatures+ DeriveDataTypeable+ DeriveFoldable+ DeriveFunctor+ DeriveGeneric+ DeriveTraversable+ EmptyDataDecls+ FlexibleContexts+ FlexibleInstances+ FunctionalDependencies+ GADTs+ GeneralizedNewtypeDeriving+ LambdaCase+ LiberalTypeSynonyms+ MagicHash+ MultiParamTypeClasses+ MultiWayIf+ OverloadedStrings+ ParallelListComp+ PatternGuards+ PatternSynonyms+ QuasiQuotes+ RankNTypes+ RecordWildCards+ ScopedTypeVariables+ StandaloneDeriving+ TemplateHaskell+ TupleSections+ TypeFamilies+ TypeOperators+ UnboxedTuples++ default-language: Haskell2010+ main-is: Main.hs build-depends:- deferred-folds,- QuickCheck >=2.8.1 && <3,- quickcheck-instances >=0.3.11 && <0.4,- rerebase <2,- tasty >=0.12 && <2,- tasty-hunit >=0.9 && <0.11,- tasty-quickcheck >=0.9 && <0.11,+ , deferred-folds+ , quickcheck-instances >=0.3.11 && <0.4+ , rerebase <2+ , tasty >=0.12 && <2+ , tasty-quickcheck >=0.9 && <0.11
library/DeferredFolds/Defs/Unfoldl.hs view
@@ -1,3 +1,5 @@+{-# OPTIONS_GHC -Wno-redundant-constraints -Wno-orphans #-}+ module DeferredFolds.Defs.Unfoldl where import qualified Data.ByteString as ByteString@@ -7,7 +9,6 @@ import DeferredFolds.Prelude hiding (fold) import qualified DeferredFolds.Prelude as A import DeferredFolds.Types-import qualified DeferredFolds.UnfoldlM as B deriving instance Functor Unfoldl @@ -53,10 +54,10 @@ {-# INLINE foldl' #-} foldl' step init (Unfoldl run) = run step init -instance Eq a => Eq (Unfoldl a) where+instance (Eq a) => Eq (Unfoldl a) where (==) left right = toList left == toList right -instance Show a => Show (Unfoldl a) where+instance (Show a) => Show (Unfoldl a) where show = show . toList instance IsList (Unfoldl a) where@@ -81,7 +82,7 @@ -- | Construct from any foldable {-# INLINE foldable #-}-foldable :: Foldable foldable => foldable a -> Unfoldl a+foldable :: (Foldable foldable) => foldable a -> Unfoldl a foldable foldable = Unfoldl (\step init -> A.foldl' step init foldable) -- | Filter the values given a predicate
library/DeferredFolds/Defs/UnfoldlM.hs view
@@ -1,3 +1,5 @@+{-# OPTIONS_GHC -Wno-redundant-constraints -Wno-orphans #-}+ module DeferredFolds.Defs.UnfoldlM where import qualified Data.ByteString.Internal as ByteString@@ -6,21 +8,21 @@ import qualified DeferredFolds.Prelude as A import DeferredFolds.Types -deriving instance Functor m => Functor (UnfoldlM m)+deriving instance (Functor m) => Functor (UnfoldlM m) -instance Monad m => Applicative (UnfoldlM m) where+instance (Monad m) => Applicative (UnfoldlM m) where pure x = UnfoldlM (\step init -> step init x) (<*>) = ap -instance Monad m => Alternative (UnfoldlM m) where+instance (Monad m) => Alternative (UnfoldlM m) where empty = UnfoldlM (const return) {-# INLINE (<|>) #-} (<|>) (UnfoldlM left) (UnfoldlM right) = UnfoldlM (\step init -> left step init >>= right step) -instance Monad m => Monad (UnfoldlM m) where+instance (Monad m) => Monad (UnfoldlM m) where return = pure {-# INLINE (>>=) #-} (>>=) (UnfoldlM left) rightK =@@ -31,17 +33,17 @@ right step output in left newStep init -instance Monad m => MonadPlus (UnfoldlM m) where+instance (Monad m) => MonadPlus (UnfoldlM m) where mzero = empty mplus = (<|>) instance MonadTrans UnfoldlM where lift m = UnfoldlM (\step init -> m >>= step init) -instance Monad m => Semigroup (UnfoldlM m a) where+instance (Monad m) => Semigroup (UnfoldlM m a) where (<>) = (<|>) -instance Monad m => Monoid (UnfoldlM m a) where+instance (Monad m) => Monoid (UnfoldlM m a) where mempty = empty mappend = (<>) @@ -57,10 +59,10 @@ where identityStep state input = return (step state input) -instance Eq a => Eq (UnfoldlM Identity a) where+instance (Eq a) => Eq (UnfoldlM Identity a) where (==) left right = toList left == toList right -instance Show a => Show (UnfoldlM Identity a) where+instance (Show a) => Show (UnfoldlM Identity a) where show = show . toList instance IsList (UnfoldlM Identity a) where@@ -70,23 +72,23 @@ -- | Check whether it's empty {-# INLINE null #-}-null :: Monad m => UnfoldlM m input -> m Bool+null :: (Monad m) => UnfoldlM m input -> m Bool null (UnfoldlM run) = run (\_ _ -> return False) True -- | Perform a monadic strict left fold {-# INLINE foldlM' #-}-foldlM' :: Monad m => (output -> input -> m output) -> output -> UnfoldlM m input -> m output+foldlM' :: (Monad m) => (output -> input -> m output) -> output -> UnfoldlM m input -> m output foldlM' step init (UnfoldlM run) = run step init -- | A more efficient implementation of mapM_ {-# INLINE mapM_ #-}-mapM_ :: Monad m => (input -> m ()) -> UnfoldlM m input -> m ()+mapM_ :: (Monad m) => (input -> m ()) -> UnfoldlM m input -> m () mapM_ step = foldlM' (const step) () -- | Same as 'mapM_' with arguments flipped {-# INLINE forM_ #-}-forM_ :: Monad m => UnfoldlM m input -> (input -> m ()) -> m ()+forM_ :: (Monad m) => UnfoldlM m input -> (input -> m ()) -> m () forM_ = flip mapM_ -- | Apply a Gonzalez fold@@ -96,7 +98,7 @@ -- | Apply a monadic Gonzalez fold {-# INLINE foldM #-}-foldM :: Monad m => FoldM m input output -> UnfoldlM m input -> m output+foldM :: (Monad m) => FoldM m input output -> UnfoldlM m input -> m output foldM (FoldM step init extract) view = do initialState <- init@@ -105,7 +107,7 @@ -- | Lift a fold input mapping function into a mapping of unfolds {-# INLINE mapFoldMInput #-}-mapFoldMInput :: Monad m => (forall x. FoldM m b x -> FoldM m a x) -> UnfoldlM m a -> UnfoldlM m b+mapFoldMInput :: (Monad m) => (forall x. FoldM m b x -> FoldM m a x) -> UnfoldlM m a -> UnfoldlM m b mapFoldMInput newFoldM unfoldM = UnfoldlM $ \step init -> foldM (newFoldM (FoldM step (return init) return)) unfoldM -- | Construct from any foldable@@ -115,25 +117,25 @@ -- | Construct from a specification of how to execute a left-fold {-# INLINE foldlRunner #-}-foldlRunner :: Monad m => (forall x. (x -> a -> x) -> x -> x) -> UnfoldlM m a+foldlRunner :: (Monad m) => (forall x. (x -> a -> x) -> x -> x) -> UnfoldlM m a foldlRunner run = UnfoldlM (\stepM state -> run (\stateM a -> stateM >>= \state -> stepM state a) (return state)) -- | Construct from a specification of how to execute a right-fold {-# INLINE foldrRunner #-}-foldrRunner :: Monad m => (forall x. (a -> x -> x) -> x -> x) -> UnfoldlM m a+foldrRunner :: (Monad m) => (forall x. (a -> x -> x) -> x -> x) -> UnfoldlM m a foldrRunner run = UnfoldlM (\stepM -> run (\x k z -> stepM z x >>= k) return) -unfoldr :: Monad m => Unfoldr a -> UnfoldlM m a+unfoldr :: (Monad m) => Unfoldr a -> UnfoldlM m a unfoldr (Unfoldr unfoldr) = foldrRunner unfoldr -- | Filter the values given a predicate {-# INLINE filter #-}-filter :: Monad m => (a -> m Bool) -> UnfoldlM m a -> UnfoldlM m a+filter :: (Monad m) => (a -> m Bool) -> UnfoldlM m a -> UnfoldlM m a filter test (UnfoldlM run) = UnfoldlM (\step -> run (\state element -> test element >>= bool (return state) (step state element))) -- | Ints in the specified inclusive range {-# INLINE intsInRange #-}-intsInRange :: Monad m => Int -> Int -> UnfoldlM m Int+intsInRange :: (Monad m) => Int -> Int -> UnfoldlM m Int intsInRange from to = UnfoldlM $ \step init -> let loop !state int =@@ -175,7 +177,7 @@ -- | Bytes of a short bytestring {-# INLINE shortByteStringBytes #-}-shortByteStringBytes :: Monad m => ShortByteString -> UnfoldlM m Word8+shortByteStringBytes :: (Monad m) => ShortByteString -> UnfoldlM m Word8 shortByteStringBytes (ShortByteString.SBS ba#) = primArray (PrimArray ba#) -- | Elements of a prim array
library/DeferredFolds/Defs/Unfoldr.hs view
@@ -1,3 +1,5 @@+{-# OPTIONS_GHC -Wno-redundant-constraints -Wno-orphans #-}+ module DeferredFolds.Defs.Unfoldr where import qualified Data.ByteString as ByteString@@ -56,10 +58,10 @@ traverse f (Unfoldr unfoldr) = unfoldr (\a next -> liftA2 cons (f a) next) (pure mempty) -instance Eq a => Eq (Unfoldr a) where+instance (Eq a) => Eq (Unfoldr a) where (==) left right = toList left == toList right -instance Show a => Show (Unfoldr a) where+instance (Show a) => Show (Unfoldr a) where show = show . toList instance IsList (Unfoldr a) where@@ -75,7 +77,7 @@ -- | Apply a monadic Gonzalez fold {-# INLINE foldM #-}-foldM :: Monad m => FoldM m input output -> Unfoldr input -> m output+foldM :: (Monad m) => FoldM m input output -> Unfoldr input -> m output foldM (FoldM step init extract) (Unfoldr unfoldr) = init >>= unfoldr (\input next state -> step state input >>= next) return >>= extract @@ -86,7 +88,7 @@ -- | Construct from any foldable {-# INLINE foldable #-}-foldable :: Foldable foldable => foldable a -> Unfoldr a+foldable :: (Foldable foldable) => foldable a -> Unfoldr a foldable = foldrAndContainer foldr -- | Elements of IntSet.@@ -195,53 +197,53 @@ -- | Elements of a vector {-# INLINE vector #-}-vector :: GenericVector.Vector vector a => vector a -> Unfoldr a+vector :: (GenericVector.Vector vector a) => vector a -> Unfoldr a vector vector = Unfoldr $ \step state -> GenericVector.foldr step state vector -- | Elements of a vector coming paired with indices {-# INLINE vectorWithIndices #-}-vectorWithIndices :: GenericVector.Vector vector a => vector a -> Unfoldr (Int, a)+vectorWithIndices :: (GenericVector.Vector vector a) => vector a -> Unfoldr (Int, a) vectorWithIndices vector = Unfoldr $ \step state -> GenericVector.ifoldr (\index a -> step (index, a)) state vector -- | -- Binary digits of a non-negative integral number.-binaryDigits :: Integral a => a -> Unfoldr a+binaryDigits :: (Integral a) => a -> Unfoldr a binaryDigits = reverse . reverseBinaryDigits -- | -- Binary digits of a non-negative integral number in reverse order.-reverseBinaryDigits :: Integral a => a -> Unfoldr a+reverseBinaryDigits :: (Integral a) => a -> Unfoldr a reverseBinaryDigits = reverseDigits 2 -- | -- Octal digits of a non-negative integral number.-octalDigits :: Integral a => a -> Unfoldr a+octalDigits :: (Integral a) => a -> Unfoldr a octalDigits = reverse . reverseOctalDigits -- | -- Octal digits of a non-negative integral number in reverse order.-reverseOctalDigits :: Integral a => a -> Unfoldr a+reverseOctalDigits :: (Integral a) => a -> Unfoldr a reverseOctalDigits = reverseDigits 8 -- | -- Decimal digits of a non-negative integral number.-decimalDigits :: Integral a => a -> Unfoldr a+decimalDigits :: (Integral a) => a -> Unfoldr a decimalDigits = reverse . reverseDecimalDigits -- | -- Decimal digits of a non-negative integral number in reverse order. -- More efficient than 'decimalDigits'.-reverseDecimalDigits :: Integral a => a -> Unfoldr a+reverseDecimalDigits :: (Integral a) => a -> Unfoldr a reverseDecimalDigits = reverseDigits 10 -- | -- Hexadecimal digits of a non-negative number.-hexadecimalDigits :: Integral a => a -> Unfoldr a+hexadecimalDigits :: (Integral a) => a -> Unfoldr a hexadecimalDigits = reverse . reverseHexadecimalDigits -- | -- Hexadecimal digits of a non-negative number in reverse order.-reverseHexadecimalDigits :: Integral a => a -> Unfoldr a+reverseHexadecimalDigits :: (Integral a) => a -> Unfoldr a reverseHexadecimalDigits = reverseDigits 16 -- |@@ -255,7 +257,7 @@ -- binaryDigits = 'reverse' . 'reverseDigits' 2 -- @ reverseDigits ::- Integral a =>+ (Integral a) => -- | Radix a -> -- | Number@@ -298,7 +300,7 @@ -- | -- Indices of set bits.-setBitIndices :: FiniteBits a => a -> Unfoldr Int+setBitIndices :: (FiniteBits a) => a -> Unfoldr Int setBitIndices a = let !size = finiteBitSize a in Unfoldr $ \step state ->@@ -313,7 +315,7 @@ -- | -- Indices of unset bits.-unsetBitIndices :: FiniteBits a => a -> Unfoldr Int+unsetBitIndices :: (FiniteBits a) => a -> Unfoldr Int unsetBitIndices a = let !size = finiteBitSize a in Unfoldr $ \step state ->
library/DeferredFolds/Defs/UnfoldrM.hs view
@@ -3,7 +3,7 @@ import DeferredFolds.Prelude import DeferredFolds.Types -unfoldr :: Monad m => Unfoldr a -> UnfoldrM m a+unfoldr :: (Monad m) => Unfoldr a -> UnfoldrM m a unfoldr (Unfoldr unfoldr) = UnfoldrM $ \stepM -> let step input act state = stepM input state >>= act in unfoldr step return
library/DeferredFolds/Prelude.hs view
@@ -73,7 +73,6 @@ import System.Mem as Exports import System.Mem.StableName as Exports import System.Timeout as Exports-import Text.ParserCombinators.ReadP as Exports (ReadP, ReadS, readP_to_S, readS_to_P) import Text.ParserCombinators.ReadPrec as Exports (ReadPrec, readP_to_Prec, readPrec_to_P, readPrec_to_S, readS_to_Prec) import Text.Printf as Exports (hPrintf, printf) import Text.Read as Exports (Read (..), readEither, readMaybe)
library/DeferredFolds/Types.hs view
@@ -1,7 +1,5 @@ module DeferredFolds.Types where -import DeferredFolds.Prelude- -- | -- A projection on data, which only knows how to execute a strict left-fold. --
library/DeferredFolds/Util/TextArray.hs view
@@ -3,9 +3,6 @@ module DeferredFolds.Util.TextArray where import Data.Text.Array-import qualified Data.Text.Internal as TextInternal-import qualified Data.Text.Internal.Encoding.Utf16 as TextUtf16-import qualified Data.Text.Internal.Unsafe.Char as TextChar import qualified Data.Text.Unsafe as TextUnsafe import DeferredFolds.Prelude hiding (Array)
test/Main.hs view
@@ -2,15 +2,12 @@ import qualified Data.Text as Text import qualified DeferredFolds.Unfoldr as Unfoldr-import qualified Test.QuickCheck as QuickCheck-import Test.QuickCheck.Instances-import qualified Test.QuickCheck.Property as QuickCheck+import Test.QuickCheck.Instances () import Test.Tasty-import Test.Tasty.HUnit import Test.Tasty.QuickCheck-import Test.Tasty.Runners import Prelude +main :: IO () main = defaultMain $ testGroup "All" $@@ -47,10 +44,6 @@ c == '\n' || c == '\r' isSpaceButNotNewline c = isSpace c && not (isNewline c)- normalize separator condition =- Text.split condition- >>> filter (not . Text.null)- >>> Text.intercalate separator expected = text & Text.split isNewline