ConstraintKinds 1.1.0.0 → 1.3.0
raw patch · 6 files changed
+20/−192 lines, 6 filesdep ~dlistPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: dlist
API changes (from Hackage documentation)
- Control.ConstraintKinds.Filterable: class Filterable f where type family FilterableConstraint f x :: Constraint type instance FilterableConstraint f x = ()
- Control.ConstraintKinds.Filterable: filter :: (Filterable f, FilterableConstraint f a) => (a -> Bool) -> f a -> f a
- Control.ConstraintKinds.Filterable: ifilter :: (Filterable f, FilterableConstraint f a) => (Int -> a -> Bool) -> f a -> f a
- Control.ConstraintKinds.Filterable: instance Filterable Vector
- Control.ConstraintKinds.Filterable: instance Filterable []
- Control.ConstraintKinds.Partitionable: class Partitionable t where type family PartitionableConstraint t x :: Constraint type instance PartitionableConstraint t x = ()
- Control.ConstraintKinds.Partitionable: instance Partitionable Vector
- Control.ConstraintKinds.Partitionable: instance Partitionable []
- Control.ConstraintKinds.Partitionable: partition :: (Partitionable t, PartitionableConstraint t a) => Int -> t a -> [t a]
- Control.ConstraintKinds.Traversable: class (Functor t, Foldable t) => Traversable t where type family TraversableConstraint t x :: Constraint type instance TraversableConstraint t x = () sequenceA = traverse id sequence = mapM id
- Control.ConstraintKinds.Traversable: instance Traversable Vector
- Control.ConstraintKinds.Traversable: instance Traversable []
- Control.ConstraintKinds.Traversable: mapM :: (Traversable t, TraversableConstraint t a, TraversableConstraint t b, FunctorConstraint t a, Monad m) => (a -> m b) -> t a -> m (t b)
- Control.ConstraintKinds.Traversable: sequence :: (Traversable t, TraversableConstraint t a, TraversableConstraint t b, TraversableConstraint t (m a), FunctorConstraint t (m a), Monad m) => t (m a) -> m (t a)
- Control.ConstraintKinds.Traversable: sequenceA :: (Traversable t, TraversableConstraint t a, TraversableConstraint t b, TraversableConstraint t (f a), FunctorConstraint t (f a), Applicative f) => t (f a) -> f (t a)
- Control.ConstraintKinds.Traversable: traverse :: (Traversable t, TraversableConstraint t a, TraversableConstraint t b, FunctorConstraint t (f b), FunctorConstraint t a, Applicative f) => (a -> f b) -> t a -> f (t b)
- Control.ConstraintKinds.Foldable: class Foldable t where type family FoldableConstraint t x :: Constraint type instance FoldableConstraint t x = () fold = foldMap id foldMap f = foldr (mappend . f) mempty foldr' f z0 xs = foldl f' id xs z0 where f' k x z = k $! f x z
+ Control.ConstraintKinds.Foldable: class Foldable t where type family FoldableConstraint t x :: Constraint type instance FoldableConstraint t x = () fold = foldMap id foldMap f = foldr (mappend . f) mempty
- Control.ConstraintKinds.Foldable: foldl :: (Foldable t, FoldableConstraint t a, FoldableConstraint t b) => (a -> b -> a) -> a -> t b -> a
+ Control.ConstraintKinds.Foldable: foldl :: (Foldable t, FoldableConstraint t b) => (a -> b -> a) -> a -> t b -> a
- Control.ConstraintKinds.Foldable: foldl' :: (Foldable t, FoldableConstraint t a, FoldableConstraint t b) => (a -> b -> a) -> a -> t b -> a
+ Control.ConstraintKinds.Foldable: foldl' :: (Foldable t, FoldableConstraint t b) => (a -> b -> a) -> a -> t b -> a
- Control.ConstraintKinds.Foldable: foldr :: (Foldable t, FoldableConstraint t a, FoldableConstraint t b) => (a -> b -> b) -> b -> t a -> b
+ Control.ConstraintKinds.Foldable: foldr :: (Foldable t, FoldableConstraint t a) => (a -> b -> b) -> b -> t a -> b
- Control.ConstraintKinds.Foldable: foldr' :: (Foldable t, FoldableConstraint t a, FoldableConstraint t (b -> b), FoldableConstraint t b) => (a -> b -> b) -> b -> t a -> b
+ Control.ConstraintKinds.Foldable: foldr' :: (Foldable t, FoldableConstraint t a) => (a -> b -> b) -> b -> t a -> b
Files
- ConstraintKinds.cabal +2/−5
- src/Control/ConstraintKinds.hs +6/−6
- src/Control/ConstraintKinds/Filterable.hs +0/−40
- src/Control/ConstraintKinds/Foldable.hs +12/−8
- src/Control/ConstraintKinds/Partitionable.hs +0/−55
- src/Control/ConstraintKinds/Traversable.hs +0/−78
ConstraintKinds.cabal view
@@ -1,5 +1,5 @@ Name: ConstraintKinds-Version: 1.1.0.0+Version: 1.3.0 Synopsis: Repackages standard type classes with the ConstraintKinds extension Description: This module provides more flexible versions of common type classes that use the ConstraintKinds extension. This allows us to make types that require constraints instances of the popular classes. For example, we reimplement Functor and Foldable using the ContraintKinds style. This allows us to manipulate lists and unboxed vectors using the same functions. .@@ -20,17 +20,14 @@ base >= 3 && < 5, ghc-prim, vector >= 0.9,- dlist >= 0.5+ dlist == 0.5 hs-source-dirs: src ghc-options: -rtsopts -auto-all -caf-all Exposed-modules: Control.ConstraintKinds Control.ConstraintKinds.Applicative- Control.ConstraintKinds.Filterable Control.ConstraintKinds.Foldable Control.ConstraintKinds.Functor Control.ConstraintKinds.Monad- Control.ConstraintKinds.Partitionable Control.ConstraintKinds.Pointed- Control.ConstraintKinds.Traversable
src/Control/ConstraintKinds.hs view
@@ -3,22 +3,22 @@ -- * Modules module Control.ConstraintKinds.Applicative- , module Control.ConstraintKinds.Filterable+-- , module Control.ConstraintKinds.Filterable , module Control.ConstraintKinds.Foldable , module Control.ConstraintKinds.Functor , module Control.ConstraintKinds.Monad- , module Control.ConstraintKinds.Partitionable+-- , module Control.ConstraintKinds.Partitionable , module Control.ConstraintKinds.Pointed- , module Control.ConstraintKinds.Traversable+-- , module Control.ConstraintKinds.Traversable ) where import Control.ConstraintKinds.Applicative-import Control.ConstraintKinds.Filterable+-- import Control.ConstraintKinds.Filterable import Control.ConstraintKinds.Foldable import Control.ConstraintKinds.Functor import Control.ConstraintKinds.Monad-import Control.ConstraintKinds.Partitionable+-- import Control.ConstraintKinds.Partitionable import Control.ConstraintKinds.Pointed-import Control.ConstraintKinds.Traversable+-- import Control.ConstraintKinds.Traversable
− src/Control/ConstraintKinds/Filterable.hs
@@ -1,40 +0,0 @@-{-# LANGUAGE ConstraintKinds #-}-{-# LANGUAGE TypeFamilies #-}--module Control.ConstraintKinds.Filterable- where--import GHC.Prim--import qualified Data.Foldable as F-import qualified Data.List as L-import qualified Data.Traversable as T-import qualified Data.Vector as V-import qualified Data.Vector.Unboxed as VU-import qualified Data.Vector.Generic as G-import qualified Prelude as P--class Filterable f where- type FilterableConstraint f x :: Constraint- type FilterableConstraint f x = ()-- filter :: (FilterableConstraint f a) => (a -> P.Bool) -> f a -> f a- ifilter :: (FilterableConstraint f a) => (P.Int -> a -> P.Bool) -> f a -> f a--instance Filterable [] where- filter = L.filter- ifilter cond xs = go 0 xs- where- go n [] = []- go n (x:xs) = if cond n x- then x:(go (n P.+ 1) xs)- else go (n P.+ 1) xs- -instance Filterable V.Vector where- filter = V.filter- ifilter = V.ifilter- -instance Filterable VU.Vector where- type FilterableConstraint VU.Vector x = VU.Unbox x - filter = VU.filter- ifilter = VU.ifilter
src/Control/ConstraintKinds/Foldable.hs view
@@ -28,9 +28,10 @@ type FoldableConstraint t x = () -- I was too lazy to work out the new default instances for these because all the important structures already provide the instances. Also, it adds additional constraints into the functions that look ugly, and I'm not sure if it affects the functionality.- foldr :: (FoldableConstraint t a, FoldableConstraint t b) => (a -> b -> b) -> b -> t a -> b- foldl :: (FoldableConstraint t a, FoldableConstraint t b) => (a -> b -> a) -> a -> t b -> a- foldl' :: (FoldableConstraint t a, FoldableConstraint t b) => (a -> b -> a) -> a -> t b -> a+ foldr :: (FoldableConstraint t a) => (a -> b -> b) -> b -> t a -> b+ foldr' :: (FoldableConstraint t a) => (a -> b -> b) -> b -> t a -> b+ foldl :: (FoldableConstraint t b) => (a -> b -> a) -> a -> t b -> a+ foldl' :: (FoldableConstraint t b) => (a -> b -> a) -> a -> t b -> a foldr1 :: (FoldableConstraint t a) => (a -> a -> a) -> t a -> a foldl1 :: (FoldableConstraint t a) => (a -> a -> a) -> t a -> a @@ -41,9 +42,6 @@ foldMap :: (FoldableConstraint t a, FoldableConstraint t m, Monoid m) => (a -> m) -> t a -> m foldMap f = foldr (mappend . f) mempty - foldr' :: (FoldableConstraint t a, FoldableConstraint t (b->b), FoldableConstraint t b) => (a -> b -> b) -> b -> t a -> b- foldr' f z0 xs = foldl f' id xs z0- where f' k x z = k $! f x z ------------------------------------------------------------------------------- -- functions@@ -58,13 +56,15 @@ instance Foldable [] where type FoldableConstraint [] x = () {-# INLINE foldr #-}+ {-# INLINE foldr' #-} {-# INLINE foldl #-} {-# INLINE foldl' #-} {-# INLINE foldr1 #-} {-# INLINE foldl1 #-} - foldr = L.foldr- foldl = L.foldl+ foldr = L.foldr+ foldr' = L.foldr+ foldl = L.foldl foldl' = L.foldl' foldr1 = L.foldr1 foldl1 = L.foldl1@@ -76,12 +76,14 @@ instance Foldable V.Vector where type FoldableConstraint V.Vector x = () {-# INLINE foldr #-}+ {-# INLINE foldr' #-} {-# INLINE foldl #-} {-# INLINE foldl' #-} {-# INLINE foldr1 #-} {-# INLINE foldl1 #-} foldr = V.foldr+ foldr' = V.foldr' foldl = V.foldl foldl' = V.foldl' foldr1 = V.foldr1@@ -90,12 +92,14 @@ instance Foldable VU.Vector where type FoldableConstraint VU.Vector x = VU.Unbox x {-# INLINE foldr #-}+ {-# INLINE foldr' #-} {-# INLINE foldl #-} {-# INLINE foldl' #-} {-# INLINE foldr1 #-} {-# INLINE foldl1 #-} foldr = VU.foldr+ foldr' = VU.foldr' foldl = VU.foldl foldl' = VU.foldl' foldr1 = VU.foldr1
− src/Control/ConstraintKinds/Partitionable.hs
@@ -1,55 +0,0 @@-{-# LANGUAGE ConstraintKinds #-}-{-# LANGUAGE TypeFamilies #-}--module Control.ConstraintKinds.Partitionable- where--import GHC.Prim--import qualified Data.Foldable as F-import qualified Data.List as L-import qualified Data.Traversable as T-import qualified Data.Vector as V-import qualified Data.Vector.Unboxed as VU-import qualified Data.Vector.Generic as G--- import qualified Prelude as P--- import Prelude (($),fromIntegral,(+),(-),(/),(*))--class Partitionable t where- type PartitionableConstraint t x :: Constraint- type PartitionableConstraint t x = ()-- partition :: (PartitionableConstraint t a) => Int -> t a -> [t a]--instance Partitionable [] where- partition n xs = [map snd $ filter (\(i,x)->i `mod` n==j) ixs | j<-[0..n-1]]- where- ixs = addIndex 0 xs- addIndex i [] = []- addIndex i (x:xs) = (i,x):(addIndex (i+1) xs)- --instance Partitionable V.Vector where- partition n vec = go 0- where- go i = if i>=V.length vec- then []- else (V.slice i len vec):(go $ i+lenmax)- where- len = if i+lenmax >= V.length vec- then (V.length vec)-i- else lenmax- lenmax = ceiling $ (fromIntegral $ V.length vec) / (fromIntegral n)--instance Partitionable VU.Vector where- type PartitionableConstraint VU.Vector x = VU.Unbox x- partition n vec = go 0- where- go i = if i>=VU.length vec- then []- else (VU.slice i len vec):(go $ i+lenmax)- where- len = if i+lenmax >= VU.length vec- then (VU.length vec)-i- else lenmax- lenmax = ceiling $ (fromIntegral $ VU.length vec) / (fromIntegral n)
− src/Control/ConstraintKinds/Traversable.hs
@@ -1,78 +0,0 @@-{-# LANGUAGE ConstraintKinds #-}-{-# LANGUAGE TypeFamilies #-}--module Control.ConstraintKinds.Traversable- where--import GHC.Prim-import Control.Applicative-import Control.Monad hiding (Functor,fmap,mapM)-import Prelude hiding (Functor, fmap, mapM)-import qualified Prelude as P--import qualified Data.Foldable as F-import qualified Data.List as L-import qualified Data.Traversable as T-import qualified Data.Vector as V-import qualified Data.Vector.Unboxed as VU-import qualified Data.Vector.Generic as VG---- import Control.ConstraintKinds.Applicative-import Control.ConstraintKinds.Foldable-import Control.ConstraintKinds.Functor hiding ((<$>))------------------------------------------------------------------------------------ class Traversable--class (Functor t, Foldable t) => Traversable t where- type TraversableConstraint t x :: Constraint- type TraversableConstraint t x = ()-- traverse :: (TraversableConstraint t a, TraversableConstraint t b, FunctorConstraint t (f b), FunctorConstraint t a, Applicative f) - => (a -> f b) -> t a -> f (t b)--- traverse f xs = sequenceA $ fmap f xs-- sequenceA :: (TraversableConstraint t a, TraversableConstraint t b, TraversableConstraint t (f a), FunctorConstraint t (f a), Applicative f) - => t (f a) -> f (t a)- sequenceA = traverse id-- mapM :: (TraversableConstraint t a, TraversableConstraint t b, FunctorConstraint t a{-, FunctorConstraint t (WrappedMonad m b)-}, Monad m) - => (a -> m b) -> t a -> m (t b)--- mapM f = unwrapMonad . traverse (WrapMonad . f)-- sequence :: (TraversableConstraint t a, TraversableConstraint t b, TraversableConstraint t (m a){-, FunctorConstraint t (WrappedMonad m a)-}, FunctorConstraint t (m a), Monad m) - => t (m a) -> m (t a)- sequence = mapM id- ----------------------------------------------------------------------------------- instances--instance Traversable [] where- type TraversableConstraint [] x = ()- {-# INLINE traverse #-} -- so that traverse can fuse- traverse f = Prelude.foldr cons_f (pure [])- where cons_f x ys = (:) <$> f x <*> ys-- mapM = P.mapM--instance Traversable V.Vector where- {-# INLINE traverse #-}- traverse f xs = V.fromList <$> traverse f (V.toList xs)-- {-# INLINE mapM #-}- mapM = V.mapM-- {-# INLINE sequence #-}- sequence = V.sequence--instance Traversable VU.Vector where- type TraversableConstraint VU.Vector x = VU.Unbox x-- {-# INLINE traverse #-}- traverse f xs = VU.fromList <$> traverse f (VU.toList xs)-- {-# INLINE mapM #-}- mapM = VU.mapM-- {-# INLINE sequence #-}- sequence = VG.sequence