Skip to content

Instances for Monoidal (,) () #194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Data/Profunctor/Kleisli/Linear.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ instance Control.Applicative f => Strong Either Void (Kleisli f) where
first (Kleisli f) = Kleisli (either (Data.fmap Left . f) (Control.pure . Right))
second (Kleisli g) = Kleisli (either (Control.pure . Left) (Data.fmap Right . g))

instance Control.Applicative f => Monoidal (,) () (Kleisli f) where
Kleisli f *** Kleisli g = Kleisli $ \(x,y) -> (,) Control.<$> f x Control.<*> g y
unit = Kleisli Control.pure
Comment on lines +47 to +48
Copy link
Contributor

@Divesh-Otwani Divesh-Otwani Sep 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps use -XInstanceSigs and give type signatures for (***) and unit just for readability. It's a bit of a pause figuring out the type in my head. Same for instances below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are to add instance signatures, we should go over the whole module. So this would be a separate PR.


instance Control.Applicative f => Wandering (Kleisli f) where
wander (Kleisli f) = Kleisli (Data.traverse f)

Expand Down
11 changes: 11 additions & 0 deletions src/Data/Profunctor/Linear.hs
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,20 @@ instance Strong Either Void LinearArrow where
first (LA f) = LA $ either (Left . f) Right
second (LA g) = LA $ either Left (Right . g)

instance Monoidal (,) () LinearArrow where
LA f *** LA g = LA $ \(a,x) -> (f a, g x)
unit = LA id

instance Profunctor (->) where
dimap f g h x = g (h (f x))
instance Strong (,) () (->) where
first f (x, y) = (f x, y)
instance Strong Either Void (->) where
first f (Left x) = Left (f x)
first _ (Right y) = Right y
instance Monoidal (,) () (->) where
(f *** g) (a,x) = (f a, g x)
unit () = ()

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

instance Prelude.Applicative f => Monoidal (,) () (Kleisli f) where
Kleisli f *** Kleisli g = Kleisli (\(x,y) -> (,) Prelude.<$> f x Prelude.<*> g y)
unit = Kleisli Prelude.pure

data Market a b s t = Market (b #-> t) (s #-> Either t a)
runMarket :: Market a b s t #-> (b #-> t, s #-> Either t a)
runMarket (Market f g) = (f, g)
Expand Down