git.iko.soy/semi-iso-optics
on master help sign in
Add instances for Dual categories.
commit49e56e33c8cdc9412f0012422e299fce8e12a887 authorPaweł Nowak <pawel834@gmail.com> dateFri 12 Dec 2014, 19:30 (12 years ago) parent8a6f530
3 files changed+19−1
Control/Category/Structures.hs+12 Control/SIArrow.hs+6 semi-iso.cabal+1−1
Control/Category/Structures.hs+12
@@ -1,4 +1,5 @@
11{-# LANGUAGE TypeFamilies #-}
2+{-# LANGUAGE FlexibleInstances #-}
23{-# LANGUAGE ConstraintKinds #-}
34{- |
45Module : Control.Category.Structures
@@ -20,6 +21,7 @@ import Control.Arrow (Kleisli(..))
2021import qualified Control.Arrow as BadArrow
2122import Control.Category
2223import Control.Monad
24+import Data.Semigroupoid.Dual
2325import Prelude hiding (id, (.))
2426
2527infixl 3 ***
@@ -50,6 +52,9 @@ class Category cat => Products cat where
5052instance Monad m => Products (Kleisli m) where
5153 (***) = (BadArrow.***)
5254
55+instance Products cat => Products (Dual cat) where
56+ Dual f *** Dual g = Dual $ f *** g
57+
5358instance Products (->) where
5459 (***) = (BadArrow.***)
5560
@@ -77,6 +82,9 @@ class Category cat => Coproducts cat where
7782instance Monad m => Coproducts (Kleisli m) where
7883 (+++) = (BadArrow.+++)
7984
85+instance Coproducts cat => Coproducts (Dual cat) where
86+ Dual f +++ Dual g = Dual $ f +++ g
87+
8088instance Coproducts (->) where
8189 (+++) = (BadArrow.+++)
8290
@@ -93,6 +101,10 @@ instance MonadPlus m => CatPlus (Kleisli m) where
93101 cempty = BadArrow.zeroArrow
94102 (/+/) = (BadArrow.<+>)
95103
104+instance CatPlus cat => CatPlus (Dual cat) where
105+ cempty = Dual cempty
106+ Dual f /+/ Dual g = Dual $ f /+/ g
107+
96108-- | A category transformer.
97109class CatTrans t where
98110 -- | Lift an arrow from the base category.
Control/SIArrow.hs+6
@@ -39,8 +39,10 @@ import Control.Category
3939import Control.Category.Structures
4040import Control.Lens.Cons
4141import Control.Lens.Empty
42+import Control.Lens.Iso
4243import Control.Lens.SemiIso
4344import Control.Monad
45+import Data.Semigroupoid.Dual
4446import Data.Tuple.Morph
4547import Prelude hiding (id, (.))
4648
@@ -94,6 +96,10 @@ instance MonadPlus m => SIArrow (Kleisli m) where
9496 siarr ai = Kleisli $ either fail return . apply ai
9597 sibind ai = Kleisli $ \a -> either fail (($ a) . runKleisli) $ apply ai a
9698
99+instance SIArrow cat => SIArrow (Dual cat) where
100+ siarr = Dual . sipure
101+ sibind ai = Dual $ sibind (iso id getDual . rev ai . iso getDual id)
102+
97103instance SIArrow ReifiedSemiIso' where
98104 siarr = reifySemiIso
99105 sibind ai = ReifiedSemiIso' $
semi-iso.cabal+1−1
@@ -66,6 +66,6 @@ library
6666 Control.Category.Reader
6767 Control.Category.Structures
6868 Data.Profunctor.Exposed
69− build-depends: base >= 4 && < 5, profunctors, transformers, lens, tuple-morph
69+ build-depends: base >= 4 && < 5, profunctors, transformers, lens, tuple-morph, semigroupoids
7070 default-language: Haskell2010
7171 ghc-options: -Wall