adjunctions 0.2.1 → 0.2.2
raw patch · 4 files changed
+46/−21 lines, 4 filesdep ~comonaddep ~comonad-transformersPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: comonad, comonad-transformers
API changes (from Hackage documentation)
- Data.Functor.Contravariant.Adjunction: class (Contravariant f, Contravariant g) => DualAdjunction f g | f -> g, g -> f
- Data.Functor.Contravariant.Adjunction: counitOp :: DualAdjunction f g => f (g a) -> a
- Data.Functor.Contravariant.Adjunction: leftAdjunctOp :: DualAdjunction f g => (f a -> b) -> g b -> a
- Data.Functor.Contravariant.Adjunction: rightAdjunctOp :: DualAdjunction f g => (g b -> a) -> f a -> b
- Data.Functor.Contravariant.Adjunction: unitOp :: DualAdjunction f g => g (f a) -> a
+ Data.Functor.Adjunction: instance Adjunction w m => Adjunction (EnvT e w) (ReaderT e m)
+ Data.Functor.Contravariant.DualAdjunction: class (Contravariant f, Contravariant g) => DualAdjunction f g | f -> g, g -> f
+ Data.Functor.Contravariant.DualAdjunction: counitOp :: DualAdjunction f g => f (g a) -> a
+ Data.Functor.Contravariant.DualAdjunction: leftAdjunctOp :: DualAdjunction f g => (f a -> b) -> g b -> a
+ Data.Functor.Contravariant.DualAdjunction: rightAdjunctOp :: DualAdjunction f g => (g b -> a) -> f a -> b
+ Data.Functor.Contravariant.DualAdjunction: unitOp :: DualAdjunction f g => g (f a) -> a
Files
- Data/Functor/Adjunction.hs +19/−1
- Data/Functor/Contravariant/Adjunction.hs +0/−17
- Data/Functor/Contravariant/DualAdjunction.hs +23/−0
- adjunctions.cabal +4/−3
Data/Functor/Adjunction.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE Rank2Types, MultiParamTypeClasses, FunctionalDependencies, UndecidableInstances, ImplicitParams #-}+{-# LANGUAGE Rank2Types, MultiParamTypeClasses, FunctionalDependencies, UndecidableInstances #-} ------------------------------------------------------------------------------------------- -- |@@ -17,11 +17,17 @@ , repAdjunction ) where +import Control.Applicative import Control.Monad.Instances () import Control.Monad.Trans.Identity++import Control.Monad.Trans.Reader+import Control.Comonad.Trans.Env+ import Data.Functor.Identity import Data.Functor.Compose import qualified Data.Functor.Contravariant.Adjunction as C+import qualified Data.Functor.Contravariant.DualAdjunction as C import qualified Data.Functor.Contravariant.Compose as C -- | An adjunction between Hask and Hask.@@ -51,6 +57,10 @@ unit = IdentityT . leftAdjunct IdentityT counit = rightAdjunct runIdentityT . runIdentityT +instance Adjunction w m => Adjunction (EnvT e w) (ReaderT e m) where+ unit a = ReaderT $ \e -> EnvT e <$> unit a+ counit (EnvT e w) = counit $ fmap (flip runReaderT e) w+ 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@@ -58,6 +68,14 @@ instance (C.Adjunction f g, C.DualAdjunction f' g') => Adjunction (C.Compose f' f) (C.Compose g g') where unit = C.Compose . C.leftAdjunct (C.leftAdjunctOp C.Compose) counit = C.rightAdjunctOp (C.rightAdjunct C.getCompose) . C.getCompose++-- instance (C.DualAdjunction f g, C.Adjunction f' g') => Adjunction (C.Compose g g') (C.Compose f' f) where+-- +-- This would require me to make separate compositions for contravariant adjunctions and contravariant dual-adjunctions,+-- but you can always just flip the arguments and get the opposite adjunction. This works because for f -| g : Hask -> Hask:+--+-- class Adjunction f g => DualAdjunction g f+-- instance Adjunction f g => DualAdjunction g f data Representation f x = Representation { rep :: forall a. (x -> a) -> f a
Data/Functor/Contravariant/Adjunction.hs view
@@ -1,7 +1,6 @@ {-# LANGUAGE Rank2Types, MultiParamTypeClasses, FunctionalDependencies, UndecidableInstances #-} module Data.Functor.Contravariant.Adjunction ( Adjunction(..)- , DualAdjunction(..) , Representation(..) , repAdjunction, repFlippedAdjunction ) where@@ -54,19 +53,3 @@ , unrep = leftAdjunct . const } --- | An adjunction from Hask to Hask^op--- --- > Hask (f a) b ~ Op a (g b)------ > rightAdjunct unit = id--- > leftAdjunct counit = id-class (Contravariant f, Contravariant g) => DualAdjunction f g | f -> g, g -> f where- unitOp :: g (f a) -> a- counitOp :: f (g a) -> a- leftAdjunctOp :: (f a -> b) -> g b -> a- rightAdjunctOp :: (g b -> a) -> f a -> b-- unitOp = leftAdjunctOp id- counitOp = rightAdjunctOp id- leftAdjunctOp f = unitOp . contramap f- rightAdjunctOp f = counitOp . contramap f
+ Data/Functor/Contravariant/DualAdjunction.hs view
@@ -0,0 +1,23 @@+{-# LANGUAGE Rank2Types, MultiParamTypeClasses, FunctionalDependencies, UndecidableInstances #-}+module Data.Functor.Contravariant.DualAdjunction + ( DualAdjunction(..)+ ) where++import Data.Functor.Contravariant++-- | An adjunction from Hask to Hask^op+-- +-- > Hask (f a) b ~ Op a (g b)+--+-- > rightAdjunct unit = id+-- > leftAdjunct counit = id+class (Contravariant f, Contravariant g) => DualAdjunction f g | f -> g, g -> f where+ unitOp :: g (f a) -> a+ counitOp :: f (g a) -> a+ leftAdjunctOp :: (f a -> b) -> g b -> a+ rightAdjunctOp :: (g b -> a) -> f a -> b++ unitOp = leftAdjunctOp id+ counitOp = rightAdjunctOp id+ leftAdjunctOp f = unitOp . contramap f+ rightAdjunctOp f = counitOp . contramap f
adjunctions.cabal view
@@ -1,6 +1,6 @@ name: adjunctions category: Data Structures, Adjunctions-version: 0.2.1+version: 0.2.2 license: BSD3 cabal-version: >= 1.6 license-file: LICENSE@@ -21,8 +21,8 @@ build-depends: base >= 4 && < 4.4, contravariant >= 0.1.2 && < 0.2,- comonad >= 0.6.2 && < 0.8,- comonad-transformers >= 0.6.1 && < 0.8,+ comonad >= 0.6.2.1 && < 0.8,+ comonad-transformers >= 0.6.5 && < 0.8, transformers >= 0.2.0 && < 0.3 exposed-modules:@@ -30,6 +30,7 @@ Control.Comonad.Trans.Adjoint Data.Functor.Adjunction Data.Functor.Contravariant.Adjunction+ Data.Functor.Contravariant.DualAdjunction Data.Functor.Zap ghc-options: -Wall