@@ -97,9 +97,9 @@ module Control.Lens.SemiIso (
9797 bifoldl1_
9898 ) where
9999
100−import Prelude hiding (id, (.))
101−import Control.Arrow
100+import Control.Arrow (Kleisli(..))
102101import Control.Category
102+import Control.Category.Structures
103103import Control.Lens.Internal.SemiIso
104104import Control.Lens.Iso
105105import Data.Foldable
@@ -107,6 +107,7 @@ import Data.Functor.Identity
107107import Data.Profunctor.Exposed
108108import Data.Traversable
109109import Data.Tuple.Morph
110+import Prelude hiding (id, (.))
110111
111112-- | A semi-isomorphism is a partial isomorphism with weakened laws.
112113--
@@ -140,11 +141,7 @@ instance Category ReifiedSemiIso' where
140141 id = ReifiedSemiIso' id
141142 ReifiedSemiIso' f . ReifiedSemiIso' g = ReifiedSemiIso' (g . f)
142143
143−-- | This in an __/incomplete/__ instance, 'arr' and '(&&&)' are undefined.
144−instance Arrow ReifiedSemiIso' where
145− arr = undefined
146− (&&&) = undefined
147−
144+instance Products ReifiedSemiIso' where
148145 -- TODO: pattern synonyms dont work here for some reason
149146 first (ReifiedSemiIso' ai) = withSemiIso ai $ \f g ->
150147 ReifiedSemiIso' $ cloneSemiIso $
@@ -161,6 +158,30 @@ instance Arrow ReifiedSemiIso' where
161158 semiIso (runKleisli $ Kleisli f *** Kleisli f')
162159 (runKleisli $ Kleisli g *** Kleisli g')
163160
161+instance Coproducts ReifiedSemiIso' where
162+ left (ReifiedSemiIso' ai) = withSemiIso ai $ \f g ->
163+ ReifiedSemiIso' $ cloneSemiIso $
164+ semiIso (runKleisli $ left $ Kleisli f)
165+ (runKleisli $ left $ Kleisli g)
166+
167+ right (ReifiedSemiIso' ai) = withSemiIso ai $ \f g ->
168+ ReifiedSemiIso' $ cloneSemiIso $
169+ semiIso (runKleisli $ right $ Kleisli f)
170+ (runKleisli $ right $ Kleisli g)
171+
172+ ReifiedSemiIso' ai +++ ReifiedSemiIso' ai' = ReifiedSemiIso' $
173+ withSemiIso ai $ \f g -> withSemiIso ai' $ \f' g' ->
174+ semiIso (runKleisli $ Kleisli f +++ Kleisli f')
175+ (runKleisli $ Kleisli g +++ Kleisli g')
176+
177+instance CatPlus ReifiedSemiIso' where
178+ cempty = ReifiedSemiIso' $ alwaysFailing "cempty"
179+
180+ ReifiedSemiIso' ai /+/ ReifiedSemiIso' ai' = ReifiedSemiIso' $
181+ withSemiIso ai $ \f g -> withSemiIso ai' $ \f' g' ->
182+ semiIso (runKleisli $ Kleisli f /+/ Kleisli f')
183+ (runKleisli $ Kleisli g /+/ Kleisli g')
184+
164185-- | Constructs a semi isomorphism from a pair of functions that can
165186-- fail with an error message.
166187semiIso :: (s -> Either String a) -> (b -> Either String t) -> SemiIso s t a b