Skip to content

Commit 1f88e18

Browse files
committed
Instances for Monoidal (,) ()
These are ported from #79 where they were needed for traversal-type things. These instances can't hurt. Even though I don't know what we are going to do with traversals yet.
1 parent 3ed688b commit 1f88e18

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/Data/Profunctor/Kleisli/Linear.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ instance Control.Applicative f => Strong Either Void (Kleisli f) where
4343
first (Kleisli f) = Kleisli (either (Data.fmap Left . f) (Control.pure . Right))
4444
second (Kleisli g) = Kleisli (either (Control.pure . Left) (Data.fmap Right . g))
4545

46+
instance Control.Applicative f => Monoidal (,) () (Kleisli f) where
47+
Kleisli f *** Kleisli g = Kleisli $ \(x,y) -> (,) Control.<$> f x Control.<*> g y
48+
unit = Kleisli Control.pure
49+
4650
instance Control.Applicative f => Wandering (Kleisli f) where
4751
wander (Kleisli f) = Kleisli (Data.traverse f)
4852

src/Data/Profunctor/Linear.hs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,20 @@ instance Strong Either Void LinearArrow where
8080
first (LA f) = LA $ either (Left . f) Right
8181
second (LA g) = LA $ either Left (Right . g)
8282

83+
instance Monoidal (,) () LinearArrow where
84+
LA f *** LA g = LA $ \(a,x) -> (f a, g x)
85+
unit = LA id
86+
8387
instance Profunctor (->) where
8488
dimap f g h x = g (h (f x))
8589
instance Strong (,) () (->) where
8690
first f (x, y) = (f x, y)
8791
instance Strong Either Void (->) where
8892
first f (Left x) = Left (f x)
8993
first _ (Right y) = Right y
94+
instance Monoidal (,) () (->) where
95+
(f *** g) (a,x) = (f a, g x)
96+
unit () = ()
9097

9198
data Exchange a b s t = Exchange (s #-> a) (b #-> t)
9299
instance Profunctor (Exchange a b) where
@@ -104,6 +111,10 @@ instance Prelude.Applicative f => Strong Either Void (Kleisli f) where
104111
Left x -> Prelude.fmap Left (f x)
105112
Right y -> Prelude.pure (Right y)
106113

114+
instance Prelude.Applicative f => Monoidal (,) () (Kleisli f) where
115+
Kleisli f *** Kleisli g = Kleisli (\(x,y) -> (,) Prelude.<$> f x Prelude.<*> g y)
116+
unit = Kleisli Prelude.pure
117+
107118
data Market a b s t = Market (b #-> t) (s #-> Either t a)
108119
runMarket :: Market a b s t #-> (b #-> t, s #-> Either t a)
109120
runMarket (Market f g) = (f, g)

0 commit comments

Comments
 (0)