New patches: [unrevert anonymous**20080407004313] < > { hunk ./src/Control/Category/Dual.hs 21 import Control.Category.Classes -newtype Dual k a b = Dual { runDual :: k b a } +newtype Dual k a b = Dual (k b a) -- overloaded for both bifunctors and categories +newtype DualF f a = DualF (f a) -- functor wrapper +-- todo DualB p a b for bifunctors hunk ./src/Control/Category/Dual.hs 25 -instance Category k => Category (Dual k) where - id = Dual id - f . g = Dual (runDual g . runDual f) hunk ./src/Control/Category/Dual.hs 26 -instance Bifunctor p k1 k2 k3 => Bifunctor p (Dual k1) (Dual k2) (Dual k3) where - bimap f g = Dual $ bimap (runDual f) (runDual g) +class HasDualF k where + dualf :: k (f b) (DualF f b) + undualf :: k (DualF f b) (f b) hunk ./src/Control/Category/Dual.hs 30 -instance Associative p k => Coassociative p (Dual k) where - coassociate = Dual associate +class HasDualF k => HasDual k k' | k -> k', k' -> k where -- note k' -> k causes type checking to diverge + dual :: k b a -> k' a b hunk ./src/Control/Category/Dual.hs 33 -instance Coassociative p k => Associative p (Dual k) where - associate = Dual coassociate +undual = dual hunk ./src/Control/Category/Dual.hs 35 -instance Braided p k => Braided p (Dual k) where - braid = Dual braid +instance (HasDualF k, HasDual k (Dual k)) => HasDualF (Dual k) where + undualf = undefined -- dual dualf + dualf = undefined -- dual undualf hunk ./src/Control/Category/Dual.hs 39 -instance HasProducts k => HasCoproducts (Dual k) where +instance HasDual k (Dual k) => HasDual (Dual k) k where +-- undual f = undefined -- dual (dual f) + dual f = undefined -- dual (undual f) + +instance (HasDual k (Dual k), Category k) => Category (Dual k) where + id = dual id + f . g = dual (dual g . dual f) + +instance (HasDual k1 (Dual k1), HasDual k2 (Dual k2) , HasDual k3 (Dual k3), Bifunctor p k1 k2 k3) => Bifunctor p (Dual k1) (Dual k2) (Dual k3) where + bimap f g = dual $ bimap (dual f) (dual g) + +instance (HasDual k (Dual k), Associative p k) => Coassociative p (Dual k) where + coassociate = dual associate + +instance (HasDual k (Dual k), Coassociative p k) => Associative p (Dual k) where + associate = dual coassociate + +instance (HasDual k (Dual k), Braided p k) => Braided p (Dual k) where + braid = dual braid + +instance (HasDual k (Dual k), Cartesian k) => CoCartesian (Dual k) where #ifndef __HADDOCK__ type Sum (Dual k) = Prod k #endif hunk ./src/Control/Category/Dual.hs 63 - inl = Dual fst - inr = Dual snd - f ||| g = Dual (runDual f &&& runDual g) - codiag = Dual diag + inl = dual fst + inr = dual snd + f ||| g = dual (dual f &&& dual g) + codiag = dual diag hunk ./src/Control/Category/Dual.hs 68 -instance HasCoproducts k => HasProducts (Dual k) where +instance (HasDual k (Dual k), CoCartesian k) => Cartesian (Dual k) where #ifndef __HADDOCK__ type Prod (Dual k) = Sum k #endif hunk ./src/Control/Category/Dual.hs 72 - fst = Dual inl - snd = Dual inr - f &&& g = Dual (runDual f ||| runDual g) - diag = Dual codiag + fst = dual inl + snd = dual inr + f &&& g = dual (dual f ||| dual g) + diag = dual codiag hunk ./src/Control/Category/Dual.hs 77 -instance Monoidal p k => Comonoidal p (Dual k) where - coidl = Dual idl - coidr = Dual idr +instance (HasDual k (Dual k), Monoidal p k) => Comonoidal p (Dual k) where + coidl = dual idl + coidr = dual idr hunk ./src/Control/Category/Dual.hs 81 -instance Comonoidal p k => Monoidal p (Dual k) where - idl = Dual coidl - idr = Dual coidr +instance (HasDual k (Dual k), Comonoidal p k) => Monoidal p (Dual k) where + idl = dual coidl + idr = dual coidr hunk ./src/Control/Category/Dual.hs 85 -instance HasIdentity p k => HasIdentity p (Dual k) +instance (HasDual k (Dual k), HasIdentity p k) => HasIdentity p (Dual k) #ifndef __HADDOCK__ where type Identity (Dual k) p = Identity k p #endif hunk ./src/Control/Category/Dual.hs 90 -instance Functor f k k => Functor f (Dual k) (Dual k) where - map = Dual . map . runDual +instance (HasDual k (Dual k), Functor f k k) => Functor (DualF f) (Dual k) (Dual k) where + map f = dual $ dualf . map (dual f) . undualf hunk ./src/Control/Category/Dual.hs 93 -instance Full f k k => Full f (Dual k) (Dual k) where - premap = Dual . premap . runDual +instance (HasDual k (Dual k), Full f k k) => Full (DualF f) (Dual k) (Dual k) where + premap f = dual $ premap (undualf . dual f . dualf) hunk ./src/Control/Category/Dual.hs 96 -instance Faithful f k k => Faithful f (Dual k) (Dual k) +instance (HasDual k (Dual k), Faithful f k k) => Faithful (DualF f) (Dual k) (Dual k) hunk ./src/Control/Category/Dual.hs 98 -instance Pointed f k => Copointed f (Dual k) where - extract = Dual return +instance (HasDual k (Dual k), Pointed f k) => Copointed (DualF f) (Dual k) where + extract = dual (dualf . return) hunk ./src/Control/Category/Dual.hs 101 -instance Copointed f k => Pointed f (Dual k) where - return = Dual extract +instance (HasDual k (Dual k), Copointed f k) => Pointed (DualF f) (Dual k) where + return = dual (extract . undualf) hunk ./src/Control/Category/Dual.hs 104 -instance Monad m k => Comonad m (Dual k) where - extend = Dual . bind . runDual - duplicate = Dual join +--instance (HasDual k (Dual k), Monad m k) => Comonad (DualF m) (Dual k) where +-- extend = dual . bind . dual +-- duplicate = dual join hunk ./src/Control/Category/Dual.hs 108 -instance Comonad w k => Monad w (Dual k) where - bind = Dual . extend . runDual - join = Dual duplicate +--instance (HasDual k (Dual k), Comonad w k )=> Monad (DualF w) (Dual k) where +-- bind = dual . extend . dual +-- join = dual duplicate hunk ./src/Control/Category/Dual.hs 112 -instance Adjunction f g k k => Adjunction g f (Dual k) (Dual k) where - unit = Dual counit - counit = Dual unit - leftAdjunct = Dual . rightAdjunct . runDual - rightAdjunct = Dual . leftAdjunct . runDual +-- todo: remove the restriction to endoadjunctions? and fix these! +{- +instance (HasDual k (Dual k), Adjunction f g k k => Adjunction (DualF g) (DualF f) (Dual k) (Dual k) where + unit = dual counit + counit = dual unit + leftAdjunct = dual . rightAdjunct . dual + rightAdjunct = dual . leftAdjunct . dual +-} hunk ./src/Control/Category/Dual.hs 121 -instance CCC k => CoCCC (Dual k) where +instance (HasDual k (Dual k), CCC k) => CoCCC (Dual k) where #ifndef __HADDOCK__ type Coexp (Dual k) = Exp k #endif hunk ./src/Control/Category/Dual.hs 125 - coapply = Dual apply - cocurry = Dual . curry . runDual - uncocurry = Dual . uncurry . runDual + coapply = dual apply + cocurry = dual . curry . dual + uncocurry = dual . uncurry . dual hunk ./src/Control/Category/Dual.hs 129 -instance CoCCC k => CCC (Dual k) where +instance (HasDual k (Dual k), CoCCC k) => CCC (Dual k) where #ifndef __HADDOCK__ type Exp (Dual k) = Coexp k #endif hunk ./src/Control/Category/Dual.hs 133 - apply = Dual coapply - curry = Dual . cocurry . runDual - uncurry = Dual . uncocurry . runDual + apply = dual coapply + curry = dual . cocurry . dual + uncurry = dual . uncocurry . dual hunk ./src/Control/Category/Dual.hs 137 -instance ( - Arrow k +instance + ( HasDual k (Dual k) + , Arrow k #ifndef __HADDOCK__ , Prod k ~ (,) #endif hunk ./src/Control/Category/Dual.hs 144 ) => DualArrow (Dual k) where - dualarr f = Dual (arr f) + dualarr f = dual (arr f) hunk ./src/Control/Category/Dual.hs 146 -instance ( - DualArrow k +instance + ( HasDual k (Dual k) + , DualArrow k #ifndef __HADDOCK__ , Sum k ~ (,) #endif hunk ./src/Control/Category/Dual.hs 153 ) => Arrow (Dual k) where - arr f = Dual (dualarr f) - -liftDualDual :: k a b -> Dual (Dual k) a b -liftDualDual = Dual . Dual - -lowerDualDual :: Dual (Dual k) a b -> k a b -lowerDualDual = runDual . runDual - -instance HasFunctorComposition k => HasFunctorComposition (Dual k) where - comp = Dual decomp - decomp = Dual comp + arr f = dual (dualarr f) hunk ./src/Control/Category/Dual.hs 155 -instance HasBitransform p c d e => HasBitransform p (Dual c) (Dual d) (Dual e) where - unbitransform = Dual bitransform - bitransform = Dual unbitransform +instance (HasDual k (Dual k), HasFunctorComposition k) => HasFunctorComposition (Dual k) where + comp = dual decomp + decomp = dual comp hunk ./src/Control/Category/Dual.hs 159 +instance (HasDual c (Dual c), HasDual d (Dual d), HasDual e (Dual e), HasBitransform p c d e) => HasBitransform p (Dual c) (Dual d) (Dual e) where + unbitransform = dual bitransform + bitransform = dual unbitransform } Context: [fixed up, it compiles again, added the identity functor ekmett@gmail.com**20080406090954] [verbage ekmett@gmail.com**20080406041625] [Added Full functors, groupoids, and fleshed out some others ekmett@gmail.com**20080406041146] [woops ekmett@gmail.com**20080405064453] [oops forgot Based ekmett@gmail.com**20080405064309] [bug fixces ekmett@gmail.com**20080405062223] [added comma categories and cartesian closed categories ekmett@gmail.com**20080405061520] [builds now, needs haddock ekmett@gmail.com**20080403090113] [initializing repository ekmett@gmail.com**20080403082348] Patch bundle hash: 9f63249a2d51ed4a1fd63a48d5fa6e4cf49f46db