constrained-categories 0.2.5.1 → 0.3.0.0
raw patch · 7 files changed
+112/−15 lines, 7 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
+ Control.Arrow.Constrained: flout :: (EnhancedCat k Coercion, Coercible b a, Object k a, Object k b) => p a b -> k b a
+ Control.Arrow.Constrained: follow :: (EnhancedCat k Coercion, Coercible a b, Object k a, Object k b) => p a b -> k a b
+ Control.Arrow.Constrained: instance Control.Arrow.Constrained.EnhancedCat (->) Data.Type.Coercion.Coercion
+ Control.Arrow.Constrained: pretend :: (EnhancedCat k Coercion, Object k a, Object k b) => Coercion a b -> k a a -> k b b
+ Control.Arrow.Constrained: pretendLike :: (EnhancedCat k Coercion, Coercible b a, Coercible c d, Object k a, Object k b, Object k c, Object k d) => p c d -> k a c -> k b d
+ Control.Arrow.Constrained: swallow :: (EnhancedCat k Coercion, Object k a, Object k b) => Coercion b a -> k a a -> k b b
+ Control.Arrow.Constrained: swallowLike :: (EnhancedCat k Coercion, Coercible b a, Coercible c d, Object k a, Object k b, Object k c, Object k d) => p b a -> k a c -> k b d
+ Control.Category.Constrained: instance Control.Category.Constrained.Category Data.Type.Coercion.Coercion
+ Control.Functor.Constrained: instance Control.Functor.Constrained.Functor ((,) a) Data.Type.Coercion.Coercion Data.Type.Coercion.Coercion
+ Control.Functor.Constrained: instance Control.Functor.Constrained.Functor ((->) a) Data.Type.Coercion.Coercion Data.Type.Coercion.Coercion
+ Control.Functor.Constrained: instance Control.Functor.Constrained.Functor (Data.Either.Either a) Data.Type.Coercion.Coercion Data.Type.Coercion.Coercion
+ Control.Functor.Constrained: instance Control.Functor.Constrained.Functor Data.Complex.Complex Data.Type.Coercion.Coercion Data.Type.Coercion.Coercion
+ Control.Functor.Constrained: instance Control.Functor.Constrained.Functor GHC.Base.Maybe Data.Type.Coercion.Coercion Data.Type.Coercion.Coercion
+ Control.Functor.Constrained: instance Control.Functor.Constrained.Functor GHC.Types.IO Data.Type.Coercion.Coercion Data.Type.Coercion.Coercion
+ Control.Functor.Constrained: instance Control.Functor.Constrained.Functor [] Data.Type.Coercion.Coercion Data.Type.Coercion.Coercion
+ Data.Traversable.Constrained: haskTraverse :: (Traversable t, Monoidal f (->) (->)) => (a -> f b) -> t a -> f (t b)
+ Data.Traversable.Constrained: instance Control.Applicative.Constrained.Monoidal f (->) (->) => GHC.Base.Applicative (Data.Traversable.Constrained.HaskWrapApplicative f)
+ Data.Traversable.Constrained: instance Control.Functor.Constrained.Functor f (->) (->) => GHC.Base.Functor (Data.Traversable.Constrained.HaskWrapApplicative f)
- Control.Monad.Constrained: filterM :: (PreArrow k, Monad m k, SumToProduct c k k, EndoTraversable c k, ObjectPair k Bool a, Object k (c a), Object k (m (c a)), ObjectPair k (Bool, a) (c (Bool, a)), ObjectPair k (m Bool) (m a), ObjectPair k (m (Bool, a)) (m (c (Bool, a))), PointObject k (c (Bool, a))) => a `k` m Bool -> c a `k` m (c a)
+ Control.Monad.Constrained: filterM :: (PreArrow k, Monad m k, SumToProduct c k k, EndoTraversable c k, ObjectPair k Bool a, Object k (c a), Object k (m (c a)), ObjectPair k (Bool, a) (c (Bool, a)), ObjectPair k (m Bool) (m a), ObjectPair k (m (Bool, a)) (m (c (Bool, a))), TraversalObject k c (Bool, a)) => a `k` m Bool -> c a `k` m (c a)
- Control.Monad.Constrained: forM :: (Traversable s t k l, Monoidal m k l, Function l, Object k b, Object k (t b), ObjectPair k b (t b), Object l a, Object l (s a), ObjectPair l (m b) (m (t b)), ObjectPoint k (t b)) => s a -> (a `l` m b) -> m (t b)
+ Control.Monad.Constrained: forM :: (Traversable s t k l, Monoidal m k l, Function l, Object k b, Object k (t b), ObjectPair k b (t b), Object l a, Object l (s a), ObjectPair l (m b) (m (t b)), TraversalObject k t b) => s a -> (a `l` m b) -> m (t b)
- Control.Monad.Constrained: mapM :: (Traversable s t k l, k ~ l, s ~ t, Applicative m k k, Object k a, Object k (t a), ObjectPair k b (t b), ObjectPair k (m b) (m (t b)), ObjectPoint k (t b)) => a `k` m b -> t a `k` m (t b)
+ Control.Monad.Constrained: mapM :: (Traversable s t k l, k ~ l, s ~ t, Applicative m k k, Object k a, Object k (t a), ObjectPair k b (t b), ObjectPair k (m b) (m (t b)), TraversalObject k t b) => a `k` m b -> t a `k` m (t b)
- Control.Monad.Constrained: sequence :: (Traversable t t k k, Monoidal f k k, ObjectPair k a (t a), ObjectPair k (f a) (f (t a)), Object k (t (f a)), ObjectPoint k (t a)) => t (f a) `k` f (t a)
+ Control.Monad.Constrained: sequence :: (Traversable s t k l, k ~ l, s ~ t, Monoidal f k k, ObjectPair k a (t a), ObjectPair k (f a) (f (t a)), Object k (t (f a)), TraversalObject k t a) => t (f a) `k` f (t a)
- Data.Traversable.Constrained: class (Category k, Category l, Functor s l l, Functor t k k) => Traversable s t k l | s k l -> t, t k l -> s, s t k -> l, s t l -> k where mapM = traverse
+ Data.Traversable.Constrained: class (Category k, Category l, Functor s l l, Functor t k k) => Traversable s t k l | s k l -> t, t k l -> s, s t k -> l, s t l -> k where type family TraversalObject k t b :: Constraint TraversalObject k t b = () mapM = traverse sequence = traverse id
- Data.Traversable.Constrained: forM :: (Traversable s t k l, Monoidal m k l, Function l, Object k b, Object k (t b), ObjectPair k b (t b), Object l a, Object l (s a), ObjectPair l (m b) (m (t b)), ObjectPoint k (t b)) => s a -> (a `l` m b) -> m (t b)
+ Data.Traversable.Constrained: forM :: (Traversable s t k l, Monoidal m k l, Function l, Object k b, Object k (t b), ObjectPair k b (t b), Object l a, Object l (s a), ObjectPair l (m b) (m (t b)), TraversalObject k t b) => s a -> (a `l` m b) -> m (t b)
- Data.Traversable.Constrained: mapM :: (Traversable s t k l, k ~ l, s ~ t, Applicative m k k, Object k a, Object k (t a), ObjectPair k b (t b), ObjectPair k (m b) (m (t b)), ObjectPoint k (t b)) => a `k` m b -> t a `k` m (t b)
+ Data.Traversable.Constrained: mapM :: (Traversable s t k l, k ~ l, s ~ t, Applicative m k k, Object k a, Object k (t a), ObjectPair k b (t b), ObjectPair k (m b) (m (t b)), TraversalObject k t b) => a `k` m b -> t a `k` m (t b)
- Data.Traversable.Constrained: sequence :: (Traversable t t k k, Monoidal f k k, ObjectPair k a (t a), ObjectPair k (f a) (f (t a)), Object k (t (f a)), ObjectPoint k (t a)) => t (f a) `k` f (t a)
+ Data.Traversable.Constrained: sequence :: (Traversable s t k l, k ~ l, s ~ t, Monoidal f k k, ObjectPair k a (t a), ObjectPair k (f a) (f (t a)), Object k (t (f a)), TraversalObject k t a) => t (f a) `k` f (t a)
- Data.Traversable.Constrained: traverse :: (Traversable s t k l, Monoidal f k l, Object l a, Object l (s a), ObjectPair k b (t b), ObjectPair l (f b) (f (t b)), ObjectPoint k (t b)) => a `l` f b -> s a `l` f (t b)
+ Data.Traversable.Constrained: traverse :: (Traversable s t k l, Monoidal f k l, Object l a, Object l (s a), ObjectPair k b (t b), ObjectPair l (f b) (f (t b)), TraversalObject k t b) => a `l` f b -> s a `l` f (t b)
Files
- Control/Arrow/Constrained.hs +49/−0
- Control/Category/Constrained.hs +5/−1
- Control/Category/Constrained/Prelude.hs +7/−1
- Control/Functor/Constrained.hs +10/−0
- Control/Monad/Constrained.hs +1/−1
- Data/Traversable/Constrained.hs +36/−10
- constrained-categories.cabal +4/−2
Control/Arrow/Constrained.hs view
@@ -59,6 +59,8 @@ -- * Misc utility -- ** Conditionals , choose, ifThenElse+ -- ** Coercions+ , follow, flout, pretend, swallow, pretendLike, swallowLike ) where import Prelude hiding (id, const, fst, snd, (.), ($), Functor(..), Monad(..), (=<<))@@ -69,6 +71,9 @@ import Data.Tagged import Data.Void +import Data.Coerce+import Data.Type.Coercion+ import qualified Control.Arrow as Arr infixr 1 >>>, <<<@@ -245,8 +250,11 @@ instance (Function f) => EnhancedCat (->) (ConstrainedCategory f o) where arr (ConstrainedMorphism q) = arr q +instance EnhancedCat (->) Coercion where+ arr = coerceWith + type Arrow a k = (WellPointed a, EnhancedCat a k) type ArrowChoice a k = (WellPointed a, PreArrChoice a, EnhancedCat a k) @@ -427,3 +435,44 @@ => x -> GenericAgent k a x genericPoint x = GenericAgent $ const x +++-- | Imitate a type change in a different category. This is usually possible+-- for type changes that are no-ops at runtime, in particular for newtype wrappers.+follow :: (EnhancedCat k Coercion, Coercible a b, Object k a, Object k b)+ => p a b -> k a b+follow _ = arr Coercion++-- | The opposite of 'follow'.+flout :: (EnhancedCat k Coercion, Coercible b a, Object k a, Object k b)+ => p a b -> k b a+flout _ = arr Coercion++-- | Wrap an endomorphism in inverse coercions, to have it work on any type+-- that's representationally equivalent to the one in the morphism's signature.+-- This is a specialised version of 'pretendLike'.+pretend :: (EnhancedCat k Coercion, Object k a, Object k b)+ => Coercion a b -> k a a -> k b b+pretend crc f = arr crc . f . arr (sym crc)++-- | Equivalent to @'pretend' . 'sym'@.+swallow :: (EnhancedCat k Coercion, Object k a, Object k b)+ => Coercion b a -> k a a -> k b b+swallow crc f = arr (sym crc) . f . arr crc++-- | This works much like <http://hackage.haskell.org/package/newtype-0.2/docs/Control-Newtype.html#v:over over>:+-- wrap a morphism in any coercions required so the result types match.+-- This will often be too polymorphic for the type checker; consider using the+-- more explicit 'follow' and 'flout'.+pretendLike :: ( EnhancedCat k Coercion, Coercible b a, Coercible c d+ , Object k a, Object k b, Object k c, Object k d )+ => p c d -> k a c -> k b d+pretendLike _ f = arr Coercion . f . arr Coercion+++-- | Generalised coercion analogue of+-- <http://hackage.haskell.org/package/newtype-0.2/docs/Control-Newtype.html#v:under under>.+swallowLike :: ( EnhancedCat k Coercion, Coercible b a, Coercible c d+ , Object k a, Object k b, Object k c, Object k d )+ => p b a -> k a c -> k b d+swallowLike _ f = arr Coercion . f . arr Coercion
Control/Category/Constrained.hs view
@@ -45,6 +45,8 @@ import Data.Tagged import Data.Monoid import Data.Void+import Data.Type.Coercion+import qualified Control.Category as Hask -- | In mathematics, a category is defined as a class of /objects/, plus a class of -- /morphisms/ between those objects. In Haskell, one traditionally works in@@ -399,4 +401,6 @@ ($~) = ($) -+instance Category Coercion where+ id = Hask.id+ (.) = (Hask..)
Control/Category/Constrained/Prelude.hs view
@@ -21,7 +21,9 @@ import Prelude hiding ( id, const, fst, snd, (.), ($), curry, uncurry , Functor(..), (<$>), Applicative(..), (<*>), Monad(..), (=<<), filter- , mapM, mapM_, sequence, sequence_ )+ , mapM, mapM_, sequence, sequence_+ , Foldable, foldMap, fold, traverse_, concatMap+ , Traversable, traverse ) import Control.Category.Constrained hiding (ConstrainedMorphism) import Control.Functor.Constrained@@ -29,4 +31,8 @@ import Control.Monad.Constrained hiding (MonadPlus(..), MonadZero(..), (>=>), (<=<), guard, forever, void) import Control.Arrow.Constrained (Function, ($), ifThenElse, fst, snd, const)+import Control.Applicative.Constrained++import Data.Foldable.Constrained (Foldable, foldMap, fold, traverse_, concatMap)+import Data.Traversable.Constrained (Traversable, traverse)
Control/Functor/Constrained.hs view
@@ -32,6 +32,9 @@ import Data.Void +import Data.Type.Coercion+import Data.Complex+ class ( Category r, Category t, Object t (f (UnitObject r)) ) => Functor f r t | f r -> t, f t -> r where fmap :: (Object r a, Object t (f a), Object r b, Object t (f b))@@ -95,4 +98,11 @@ filter (ConstrainedMorphism f) = ConstrainedMorphism $ filter f +instance Functor [] Coercion Coercion where fmap Coercion = Coercion+instance Functor Maybe Coercion Coercion where fmap Coercion = Coercion+instance Functor (Either a) Coercion Coercion where fmap Coercion = Coercion+instance Functor ((->) a) Coercion Coercion where fmap Coercion = Coercion+instance Functor ((,) a) Coercion Coercion where fmap Coercion = Coercion+instance Functor IO Coercion Coercion where fmap Coercion = Coercion+instance Functor Complex Coercion Coercion where fmap Coercion = Coercion
Control/Monad/Constrained.hs view
@@ -264,7 +264,7 @@ , ObjectPair k (Bool, a) (c (Bool, a)) , ObjectPair k (m Bool) (m a) , ObjectPair k (m (Bool, a)) (m (c (Bool, a)))- , PointObject k (c (Bool, a))+ , TraversalObject k c (Bool, a) ) => a `k` m Bool -> c a `k` m (c a) filterM pg = fmap (fmap snd <<< filter fst) <<< mapM (fzip <<< pg &&& pure)
Data/Traversable/Constrained.hs view
@@ -17,8 +17,9 @@ module Data.Traversable.Constrained ( module Control.Applicative.Constrained , Traversable(..)- , sequence, forM+ , forM , EndoTraversable+ , haskTraverse ) where @@ -36,37 +37,44 @@ import qualified Control.Category.Hask as Hask import qualified Control.Arrow as A +import qualified Data.Traversable as Hask+ import Control.Arrow.Constrained import Data.Monoid +import GHC.Exts (Constraint) class (Category k, Category l, Functor s l l, Functor t k k) => Traversable s t k l | s k l -> t, t k l -> s, s t k -> l, s t l -> k where+ type TraversalObject k t b :: Constraint+ type TraversalObject k t b = ()+ traverse :: ( Monoidal f k l, Object l a, Object l (s a) , ObjectPair k b (t b), ObjectPair l (f b) (f (t b)) - , ObjectPoint k (t b)+ , TraversalObject k t b ) => a `l` f b -> s a `l` f (t b) -- | 'traverse', restricted to endofunctors. May be more efficient to implement. mapM :: ( k~l, s~t, Applicative m k k , Object k a, Object k (t a), ObjectPair k b (t b), ObjectPair k (m b) (m (t b))- , ObjectPoint k (t b)+ , TraversalObject k t b ) => a `k` m b -> t a `k` m (t b) mapM = traverse -sequence :: ( Traversable t t k k, Monoidal f k k- , ObjectPair k a (t a), ObjectPair k (f a) (f (t a))- , Object k (t (f a))- , ObjectPoint k (t a)- ) => t (f a) `k` f (t a)-sequence = traverse id+ sequence :: ( k~l, s~t, Monoidal f k k+ , ObjectPair k a (t a), ObjectPair k (f a) (f (t a))+ , Object k (t (f a))+ , TraversalObject k t a+ ) => t (f a) `k` f (t a)+ sequence = traverse id instance (Arrow k (->), WellPointed k, Function k, Functor [] k k) => Traversable [] [] k k where+ type TraversalObject k [] b = PointObject k [b] traverse f = arr mM where mM [] = constPure [] `inCategoryOf` f $ mempty mM (x:xs) = fzipWith (arr $ uncurry(:)) `inCategoryOf` f @@ -74,6 +82,7 @@ instance (Arrow k (->), WellPointed k, Function k, Functor Maybe k k) => Traversable Maybe Maybe k k where+ type TraversalObject k Maybe b = PointObject k (Maybe b) traverse f = arr mM where mM Nothing = constPure Nothing `inCategoryOf` f $ mempty mM (Just x) = fmap (arr Just) . f $ x@@ -88,7 +97,7 @@ ( Traversable s t k l, Monoidal m k l, Function l , Object k b, Object k (t b), ObjectPair k b (t b) , Object l a, Object l (s a), ObjectPair l (m b) (m (t b))- , ObjectPoint k (t b)+ , TraversalObject k t b ) => s a -> (a `l` m b) -> m (t b) forM v f = traverse f $ v @@ -96,4 +105,21 @@ -- | A traversable that can be used with 'mapM'. type EndoTraversable t k = Traversable t t k k ++newtype HaskWrapApplicative f x = HaskWrapApplicative { getHWAppl :: f x }++instance (Functor f (->) (->)) => Hask.Functor (HaskWrapApplicative f) where+ fmap f (HaskWrapApplicative c) = HaskWrapApplicative $ fmap f c+instance (Monoidal f (->) (->)) => Hask.Applicative (HaskWrapApplicative f) where+ pure x = HaskWrapApplicative $ (fmap (const x) . pureUnit) ()+ HaskWrapApplicative fs <*> HaskWrapApplicative xs+ = HaskWrapApplicative $ fzipWith (uncurry ($)) (fs, xs)++-- | Use this if you want to “derive” a constrained traversable instance from a+-- given 'Hask.Traversable' one. (You will not be able to simply set+-- @'traverse' = 'Hask.traverse'@, because the latter requires the Prelude version+-- of 'Hask.Applicative', which can not be inferred from the constrained `Monoidal`.+haskTraverse :: (Hask.Traversable t, Monoidal f (->) (->))+ => (a -> f b) -> t a -> f (t b)+haskTraverse f = getHWAppl . Hask.traverse (HaskWrapApplicative . f)
constrained-categories.cabal view
@@ -1,5 +1,5 @@ Name: constrained-categories-Version: 0.2.5.1+Version: 0.3.0.0 Category: control Synopsis: Constrained clones of the category-theory type classes, using ConstraintKinds. Description: Haskell has, and makes great use of, powerful facilities from category@@ -31,6 +31,8 @@ Homepage: https://github.com/leftaroundabout/constrained-categories Build-Type: Simple Cabal-Version: >=1.10+Tested-With: GHC == 7.8.4, GHC == 7.10.2, GHC == 8.0.2+ source-repository head type: git@@ -38,7 +40,7 @@ Library Default-Language: Haskell2010- Build-Depends: base>=4.6 && <5+ Build-Depends: base>=4.7 && <5 , tagged , void Default-Extensions: ConstraintKinds