adjunctions 1.0.0 → 1.8.0
raw patch · 2 files changed
+78/−54 lines, 2 filesdep ~comonad-transformersdep ~keysdep ~representable-functorsPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: comonad-transformers, keys, representable-functors
API changes (from Hackage documentation)
- Data.Functor.Adjunction: inhabitedL :: Adjunction f u => f Void -> Void
- Data.Functor.Adjunction: uncozipF :: Functor f => Either (f a) (f b) -> f (Either a b)
- Data.Functor.Adjunction: unzipF :: Functor u => u (a, b) -> (u a, u b)
+ Data.Functor.Adjunction: absurdL :: Void -> f Void
+ Data.Functor.Adjunction: duplicateL :: Adjunction f u => f a -> f (f a)
+ Data.Functor.Adjunction: extractL :: Adjunction f u => f a -> a
+ Data.Functor.Adjunction: splitL :: Adjunction f u => f a -> (a, f ())
+ Data.Functor.Adjunction: unabsurdL :: Adjunction f u => f Void -> Void
+ Data.Functor.Adjunction: uncozipL :: Functor f => Either (f a) (f b) -> f (Either a b)
+ Data.Functor.Adjunction: unsplitL :: Functor f => a -> f () -> f a
+ Data.Functor.Adjunction: unzipR :: Functor u => u (a, b) -> (u a, u b)
Files
- Data/Functor/Adjunction.hs +73/−48
- adjunctions.cabal +5/−6
Data/Functor/Adjunction.hs view
@@ -1,5 +1,7 @@-{-# LANGUAGE Rank2Types, MultiParamTypeClasses, FunctionalDependencies, UndecidableInstances #-}-{-# LANGUAGE ImplicitParams #-}+{-# LANGUAGE Rank2Types+ , MultiParamTypeClasses+ , FunctionalDependencies+ , UndecidableInstances #-} ------------------------------------------------------------------------------------------- -- |@@ -16,17 +18,17 @@ ( Adjunction(..) , tabulateAdjunction , indexAdjunction- , zipR, unzipF- , inhabitedL- , cozipL, uncozipF+ , zipR, unzipR+ , unabsurdL, absurdL+ , cozipL, uncozipL+ , extractL, duplicateL+ , splitL, unsplitL ) where import Control.Applicative import Control.Arrow ((&&&), (|||)) import Control.Monad.Instances () import Control.Monad.Trans.Identity--import Control.Monad.Representable import Control.Monad.Trans.Reader import Control.Monad.Trans.Writer import Control.Comonad.Trans.Env@@ -34,94 +36,117 @@ import Data.Functor.Identity import Data.Functor.Compose-+import Data.Functor.Representable import Data.Void -- | An adjunction between Hask and Hask. ----- Minimal definition: both 'unit' and 'counit' or both 'leftAdjunct' and 'rightAdjunct', --- subject to the constraints imposed by the default definitions that the following laws--- should hold.+-- Minimal definition: both 'unit' and 'counit' or both 'leftAdjunct' +-- and 'rightAdjunct', subject to the constraints imposed by the +-- default definitions that the following laws should hold. -- -- > unit = leftAdjunct id -- > counit = rightAdjunct id -- > leftAdjunct f = fmap f . unit -- > rightAdjunct f = counit . fmap f ----- Any implementation is required to ensure that 'leftAdjunct' and 'rightAdjunct' witness--- an isomorphism from @Nat (f a, b)@ to @Nat (a, g b)@+-- Any implementation is required to ensure that 'leftAdjunct' and +-- 'rightAdjunct' witness an isomorphism from @Nat (f a, b)@ to +-- @Nat (a, g b)@ -- -- > rightAdjunct unit = id -- > leftAdjunct counit = id -class (Functor f, Representable u) => Adjunction f u | f -> u, u -> f where- unit :: a -> u (f a)- counit :: f (u a) -> a- leftAdjunct :: (f a -> b) -> a -> u b+class (Functor f, Representable u) => + Adjunction f u | f -> u, u -> f where+ unit :: a -> u (f a)+ counit :: f (u a) -> a+ leftAdjunct :: (f a -> b) -> a -> u b rightAdjunct :: (a -> u b) -> f a -> b- - unit = leftAdjunct id- counit = rightAdjunct id- leftAdjunct f = fmap f . unit++ unit = leftAdjunct id+ counit = rightAdjunct id+ leftAdjunct f = fmap f . unit rightAdjunct f = counit . fmap f --- | Every right adjoint is representable by its left adjoint applied to a unit element+-- | Every right adjoint is representable by its left adjoint +-- applied to a unit element -- --- Use this definition and the primitives in Data.Functor.Representable to meet the requirements--- of the superclasses of Representable.+-- Use this definition and the primitives in +-- Data.Functor.Representable to meet the requirements of the +-- superclasses of Representable. tabulateAdjunction :: Adjunction f u => (f () -> b) -> u b tabulateAdjunction f = leftAdjunct f () --- | This definition admits a default definition for the 'index' method of 'Index", one of the--- superclasses of Representable.+-- | This definition admits a default definition for the +-- 'index' method of 'Index", one of the superclasses of +-- Representable. indexAdjunction :: Adjunction f u => u b -> f a -> b indexAdjunction = rightAdjunct . const --- | A right adjoint functor admits an intrinsic notion of zipping+splitL :: Adjunction f u => f a -> (a, f ())+splitL = rightAdjunct (flip leftAdjunct () . (,))++unsplitL :: Functor f => a -> f () -> f a+unsplitL = (<$)++extractL :: Adjunction f u => f a -> a+extractL = fst . splitL++duplicateL :: Adjunction f u => f a -> f (f a)+duplicateL as = as <$ as++-- | A right adjoint functor admits an intrinsic +-- notion of zipping zipR :: Adjunction f u => (u a, u b) -> u (a, b) zipR = leftAdjunct (rightAdjunct fst &&& rightAdjunct snd) -- | Every functor in Haskell permits unzipping-unzipF :: Functor u => u (a, b) -> (u a, u b)-unzipF = fmap fst &&& fmap snd+unzipR :: Functor u => u (a, b) -> (u a, u b)+unzipR = fmap fst &&& fmap snd --- | A left adjoint must be inhabited, or we can derive bottom-inhabitedL :: Adjunction f u => f Void -> Void-inhabitedL = rightAdjunct absurd+absurdL :: Void -> f Void+absurdL = absurd +-- | A left adjoint must be inhabited, or we can derive bottom. +unabsurdL :: Adjunction f u => f Void -> Void+unabsurdL = rightAdjunct absurd+ -- | And a left adjoint must be inhabited by exactly one element cozipL :: Adjunction f u => f (Either a b) -> Either (f a) (f b) cozipL = rightAdjunct (leftAdjunct Left ||| leftAdjunct Right) -- | Every functor in Haskell permits 'uncozipping'-uncozipF :: Functor f => Either (f a) (f b) -> f (Either a b)-uncozipF = fmap Left ||| fmap Right+uncozipL :: Functor f => Either (f a) (f b) -> f (Either a b)+uncozipL = fmap Left ||| fmap Right -- Requires deprecated Impredicative types- -- limitR :: Adjunction f u => (forall a. u a) -> u (forall a. a) -- limitR = leftAdjunct (rightAdjunct (\(x :: forall a. a) -> x)) --instance Adjunction ((,)e) ((->)e) where- leftAdjunct f a e = f (e, a)+instance Adjunction ((,) e) ((->) e) where+ leftAdjunct f a e = f (e, a) rightAdjunct f ~(e, a) = f a e instance Adjunction Identity Identity where- leftAdjunct f = Identity . f . Identity+ leftAdjunct f = Identity . f . Identity rightAdjunct f = runIdentity . f . runIdentity -instance Adjunction f g => Adjunction (IdentityT f) (IdentityT g) where- unit = IdentityT . leftAdjunct IdentityT+instance Adjunction f g => + Adjunction (IdentityT f) (IdentityT g) where+ unit = IdentityT . leftAdjunct IdentityT counit = rightAdjunct runIdentityT . runIdentityT -instance Adjunction w m => Adjunction (EnvT e w) (ReaderT e m) where- unit = ReaderT . flip fmap EnvT . flip leftAdjunct+instance Adjunction w m => + Adjunction (EnvT e w) (ReaderT e m) where+ unit = ReaderT . flip fmap EnvT . flip leftAdjunct counit (EnvT e w) = rightAdjunct (flip runReaderT e) w -instance Adjunction m w => Adjunction (WriterT s m) (TracedT s w) where- unit = TracedT . leftAdjunct (\ma s -> WriterT (fmap (\a -> (a, s)) ma)) - counit = rightAdjunct (\(t, s) -> ($s) <$> runTracedT t) . runWriterT+instance Adjunction m w => + Adjunction (WriterT s m) (TracedT s w) where+ unit = TracedT . leftAdjunct (\ma s -> WriterT (fmap (\a -> (a, s)) ma)) + counit = rightAdjunct (\(t, s) -> ($s) <$> runTracedT t) . runWriterT -instance (Adjunction f g, Adjunction f' g') => Adjunction (Compose f' f) (Compose g g') where- unit = Compose . leftAdjunct (leftAdjunct Compose) +instance (Adjunction f g, Adjunction f' g') => + Adjunction (Compose f' f) (Compose g g') where+ unit = Compose . leftAdjunct (leftAdjunct Compose) counit = rightAdjunct (rightAdjunct getCompose) . getCompose
adjunctions.cabal view
@@ -1,6 +1,6 @@ name: adjunctions category: Data Structures, Adjunctions-version: 1.0.0+version: 1.8.0 license: BSD3 cabal-version: >= 1.6 license-file: LICENSE@@ -22,22 +22,21 @@ array >= 0.3.0.2 && < 0.4, base >= 4 && < 4.4, comonad >= 1.1 && < 1.2,- comonad-transformers >= 1.7 && < 1.8, containers >= 0.3 && < 0.5, contravariant >= 0.1.2 && < 0.2, distributive >= 0.2 && < 0.3,- keys >= 0.3 && < 0.4, mtl >= 2.0.1.0 && < 2.1,- representable-functors >= 0.5 && < 0.6, semigroups >= 0.5 && < 0.6, semigroupoids >= 1.2.2 && < 1.3.0, transformers >= 0.2.0 && < 0.3,- void >= 0.5.1 && < 0.6+ void >= 0.5.1 && < 0.6,+ keys >= 1.8 && < 1.9,+ comonad-transformers >= 1.8 && < 1.9,+ representable-functors >= 1.8 && < 1.9 exposed-modules: Data.Functor.Adjunction Data.Functor.Contravariant.Adjunction- Control.Comonad.Trans.Adjoint Control.Monad.Trans.Adjoint Control.Monad.Trans.Conts