packages feed

adjunctions 0.5.0 → 0.5.1

raw patch · 4 files changed

+99/−5 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Data.Functor.Composition: class Composition compose
+ Data.Functor.Composition: compose :: Composition compose => f (g x) -> compose f g x
+ Data.Functor.Composition: decompose :: Composition compose => compose f g x -> f (g x)
+ Data.Functor.Composition: instance Composition Compose
+ Data.Functor.KanExtension: Lan :: (g b -> a) -> h b -> Lan g h a
+ Data.Functor.KanExtension: Ran :: (forall b. (a -> g b) -> h b) -> Ran g h a
+ Data.Functor.KanExtension: adjointToLan :: Adjunction f g => g a -> Lan f Identity a
+ Data.Functor.KanExtension: adjointToRan :: Adjunction f g => f a -> Ran g Identity a
+ Data.Functor.KanExtension: composeLan :: (Composition compose, Functor f) => Lan f (Lan g h) a -> Lan (compose f g) h a
+ Data.Functor.KanExtension: composeRan :: Composition compose => Ran f (Ran g h) a -> Ran (compose f g) h a
+ Data.Functor.KanExtension: composedAdjointToLan :: Composition compose => Adjunction f g => compose h g a -> Lan f h a
+ Data.Functor.KanExtension: composedAdjointToRan :: (Composition compose, Adjunction f g, Functor h) => compose h f a -> Ran g h a
+ Data.Functor.KanExtension: data Lan g h a
+ Data.Functor.KanExtension: decomposeLan :: Composition compose => Lan (compose f g) h a -> Lan f (Lan g h) a
+ Data.Functor.KanExtension: decomposeRan :: (Composition compose, Functor f) => Ran (compose f g) h a -> Ran f (Ran g h) a
+ Data.Functor.KanExtension: fromLan :: Composition compose => (forall a. Lan g h a -> f a) -> h b -> compose f g b
+ Data.Functor.KanExtension: fromRan :: Composition compose => (forall a. k a -> Ran g h a) -> compose k g b -> h b
+ Data.Functor.KanExtension: instance Functor (Lan f g)
+ Data.Functor.KanExtension: instance Functor (Ran g h)
+ Data.Functor.KanExtension: lanToAdjoint :: Adjunction f g => Lan f Identity a -> g a
+ Data.Functor.KanExtension: lanToComposedAdjoint :: (Composition compose, Functor h, Adjunction f g) => Lan f h a -> compose h g a
+ Data.Functor.KanExtension: newtype Ran g h a
+ Data.Functor.KanExtension: ranToAdjoint :: Adjunction f g => Ran g Identity a -> f a
+ Data.Functor.KanExtension: ranToComposedAdjoint :: (Composition compose, Adjunction f g) => Ran g h a -> compose h f a
+ Data.Functor.KanExtension: runRan :: Ran g h a -> forall b. (a -> g b) -> h b
+ Data.Functor.KanExtension: toLan :: (Composition compose, Functor f) => (forall a. h a -> compose f g a) -> Lan g h b -> f b
+ Data.Functor.KanExtension: toRan :: (Composition compose, Functor k) => (forall a. compose k g a -> h a) -> k b -> Ran g h b

Files

Control/Comonad/Trans/Density.hs view
@@ -9,7 +9,7 @@ -- Stability   :  experimental -- Portability :  non-portable (GADTs, MPTCs) ----- The densityT comonad for a functor. aka the comonad cogenerated by a functor+-- The densityT comonad for a functor. aka the comonad generated by a functor -- The ''densityT'' term dates back to Dubuc''s 1974 thesis. The term  -- ''monad genererated by a functor'' dates back to 1972 in Street''s  -- ''Formal Theory of Monads''.
+ Data/Functor/Composition.hs view
@@ -0,0 +1,14 @@+module Data.Functor.Composition +  ( Composition(..) ) where++import Data.Functor.Compose+  +-- | We often need to distinguish between various forms of Functor-like composition in Haskell in order to please the type system.+-- This lets us work with these representations uniformly.+class Composition compose where+  decompose :: compose f g x -> f (g x)+  compose :: f (g x) -> compose f g x++instance Composition Compose where+  decompose = getCompose+  compose = Compose
+ Data/Functor/KanExtension.hs view
@@ -0,0 +1,81 @@+{-# LANGUAGE Rank2Types, GADTs #-}+-------------------------------------------------------------------------------------------+-- |+-- Module	: Data.Functor.KanExtension+-- Copyright 	: 2008-2011 Edward Kmett+-- License	: BSD+--+-- Maintainer	: Edward Kmett <ekmett@gmail.com>+-- Stability	: experimental+-- Portability	: rank 2 types+--+-------------------------------------------------------------------------------------------+module Data.Functor.KanExtension where++import Data.Functor.Identity+import Data.Functor.Adjunction+import Data.Functor.Composition++newtype Ran g h a = Ran { runRan :: forall b. (a -> g b) -> h b }++instance Functor (Ran g h) where+  fmap f m = Ran (\k -> runRan m (k . f))+ +-- | 'toRan' and 'fromRan' witness a higher kinded adjunction. from @(`'Compose'` g)@ to @'Ran' g@+toRan :: (Composition compose, Functor k) => (forall a. compose k g a -> h a) -> k b -> Ran g h b+toRan s t = Ran (s . compose . flip fmap t)++fromRan :: Composition compose => (forall a. k a -> Ran g h a) -> compose k g b -> h b+fromRan s = flip runRan id . s . decompose++composeRan :: Composition compose => Ran f (Ran g h) a -> Ran (compose f g) h a+composeRan r = Ran (\f -> runRan (runRan r (decompose . f)) id)++decomposeRan :: (Composition compose, Functor f) => Ran (compose f g) h a -> Ran f (Ran g h) a+decomposeRan r = Ran (\f -> Ran (\g -> runRan r (compose . fmap g . f)))++adjointToRan :: Adjunction f g => f a -> Ran g Identity a+adjointToRan f = Ran (\a -> Identity $ rightAdjunct a f)++ranToAdjoint :: Adjunction f g => Ran g Identity a -> f a+ranToAdjoint r = runIdentity (runRan r unit)++ranToComposedAdjoint :: (Composition compose, Adjunction f g) => Ran g h a -> compose h f a+ranToComposedAdjoint r = compose (runRan r unit)++composedAdjointToRan :: (Composition compose, Adjunction f g, Functor h) => compose h f a -> Ran g h a+composedAdjointToRan f = Ran (\a -> fmap (rightAdjunct a) (decompose f))++data Lan g h a where+  Lan :: (g b -> a) -> h b -> Lan g h a++-- 'fromLan' and 'toLan' witness a (higher kinded) adjunction between @'Lan' g@ and @(`Compose` g)@+toLan :: (Composition compose, Functor f) => (forall a. h a -> compose f g a) -> Lan g h b -> f b+toLan s (Lan f v) = fmap f . decompose $ s v++fromLan :: (Composition compose) => (forall a. Lan g h a -> f a) -> h b -> compose f g b+fromLan s = compose . s . Lan id++instance Functor (Lan f g) where+  fmap f (Lan g h) = Lan (f . g) h++adjointToLan :: Adjunction f g => g a -> Lan f Identity a+adjointToLan = Lan counit . Identity++lanToAdjoint :: Adjunction f g => Lan f Identity a -> g a+lanToAdjoint (Lan f v) = leftAdjunct f (runIdentity v)++-- | 'lanToComposedAdjoint' and 'composedAdjointToLan' witness the natural isomorphism between @Lan f h@ and @Compose h g@ given @f -| g@+lanToComposedAdjoint :: (Composition compose, Functor h, Adjunction f g) => Lan f h a -> compose h g a+lanToComposedAdjoint (Lan f v) = compose (fmap (leftAdjunct f) v)++composedAdjointToLan :: Composition compose => Adjunction f g => compose h g a -> Lan f h a+composedAdjointToLan = Lan counit . decompose++-- | 'composeLan' and 'decomposeLan' witness the natural isomorphism from @Lan f (Lan g h)@ and @Lan (f `o` g) h@+composeLan :: (Composition compose, Functor f) => Lan f (Lan g h) a -> Lan (compose f g) h a+composeLan (Lan f (Lan g h)) = Lan (f . fmap g . decompose) h++decomposeLan :: Composition compose => Lan (compose f g) h a -> Lan f (Lan g h) a+decomposeLan (Lan f h) = Lan (f . compose) (Lan id h)+
adjunctions.cabal view
@@ -1,6 +1,6 @@ name:          adjunctions category:      Data Structures, Adjunctions-version:       0.5.0+version:       0.5.1 license:       BSD3 cabal-version: >= 1.6 license-file:  LICENSE@@ -35,12 +35,11 @@     Control.Monad.Trans.Conts     Control.Monad.Trans.Contravariant.Adjoint     Data.Functor.Adjunction+    Data.Functor.Composition     Data.Functor.Contravariant.Adjunction     Data.Functor.Zap     Data.Functor.Yoneda     Data.Functor.Yoneda.Contravariant+    Data.Functor.KanExtension    ghc-options: -Wall ----    Control.Monad.Trans.Yoneda-