-
Notifications
You must be signed in to change notification settings - Fork 13
Add some bifunctors-style newtypes #22
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
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| module Data.Profunctor.Clown where | ||
|
|
||
| import Prelude | ||
|
|
||
| import Data.Profunctor (class Profunctor) | ||
| import Data.Newtype (class Newtype) | ||
| import Data.Functor.Contravariant (class Contravariant, cmap) | ||
|
|
||
| -- | Makes a trivial `Profunctor` for a `Contravariant` functor. | ||
| newtype Clown f a b = Clown (f a) | ||
|
|
||
| derive instance newtypeClown :: Newtype (Clown f a b) _ | ||
| derive newtype instance eqClown :: Eq (f a) => Eq (Clown f a b) | ||
| derive newtype instance ordClown :: Ord (f a) => Ord (Clown f a b) | ||
|
|
||
| instance showClown :: Show (f a) => Show (Clown f a b) where | ||
| show (Clown x) = "(Clown " <> show x <> ")" | ||
|
|
||
| instance functorClown :: Functor (Clown f a) where | ||
| map _ (Clown a) = Clown a | ||
|
|
||
| instance profunctorClown :: Contravariant f => Profunctor (Clown f) where | ||
| dimap f g (Clown a) = Clown (cmap f a) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| module Data.Profunctor.Cowrap where | ||
|
|
||
| import Prelude | ||
|
|
||
| import Data.Newtype (class Newtype) | ||
| import Data.Functor.Contravariant (class Contravariant) | ||
| import Data.Profunctor (class Profunctor, lmap) | ||
|
|
||
| -- | Provides a `Contravariant` over the first argument of a `Profunctor`. | ||
| newtype Cowrap p b a = Cowrap (p a b) | ||
|
|
||
| derive instance newtypeCowrap :: Newtype (Cowrap p b a) _ | ||
| derive newtype instance eqCowrap :: Eq (p a b) => Eq (Cowrap p b a) | ||
| derive newtype instance ordCowrap :: Ord (p a b) => Ord (Cowrap p b a) | ||
|
|
||
| instance showCowrap :: Show (p a b) => Show (Cowrap p b a) where | ||
| show (Cowrap x) = "(Cowrap " <> show x <> ")" | ||
|
|
||
| instance contravariantCowrap :: Profunctor p => Contravariant (Cowrap p b) where | ||
| cmap f (Cowrap a) = Cowrap (lmap f a) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| module Data.Profunctor.Join where | ||
|
|
||
| import Prelude | ||
|
|
||
| import Data.Functor.Invariant (class Invariant) | ||
| import Data.Newtype (class Newtype) | ||
| import Data.Profunctor (class Profunctor, dimap) | ||
|
|
||
| -- | Turns a `Profunctor` into a `Invariant` functor by equating the two type | ||
| -- | arguments. | ||
| newtype Join p a = Join (p a a) | ||
|
|
||
| derive instance newtypeJoin :: Newtype (Join p a) _ | ||
| derive newtype instance eqJoin :: Eq (p a a) => Eq (Join p a) | ||
| derive newtype instance ordJoin :: Ord (p a a) => Ord (Join p a) | ||
|
|
||
| instance showJoin :: Show (p a a) => Show (Join p a) where | ||
| show (Join x) = "(Join " <> show x <> ")" | ||
|
|
||
| instance invariantJoin :: Profunctor p => Invariant (Join p) where | ||
| imap f g (Join a) = Join (dimap g f a) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| module Data.Profunctor.Joker where | ||
|
|
||
| import Prelude | ||
|
|
||
| import Data.Profunctor (class Profunctor) | ||
| import Data.Newtype (class Newtype) | ||
|
|
||
| -- | Makes a trivial `Profunctor` for a covariant `Functor`. | ||
| newtype Joker f a b = Joker (f b) | ||
|
|
||
| derive instance newtypeJoker :: Newtype (Joker f a b) _ | ||
| derive newtype instance eqJoker :: Eq (f b) => Eq (Joker f a b) | ||
| derive newtype instance ordJoker :: Ord (f b) => Ord (Joker f a b) | ||
|
|
||
| instance showJoker :: Show (f b) => Show (Joker f a b) where | ||
| show (Joker x) = "(Joker " <> show x <> ")" | ||
|
|
||
| instance functorJoker :: Functor f => Functor (Joker f a) where | ||
| map f (Joker a) = Joker (map f a) | ||
|
|
||
| instance profunctorJoker :: Functor f => Profunctor (Joker f) where | ||
| dimap f g (Joker a) = Joker (map g a) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| module Data.Profunctor.Wrap where | ||
|
|
||
| import Prelude | ||
|
|
||
| import Data.Newtype (class Newtype) | ||
| import Data.Profunctor (class Profunctor, rmap) | ||
|
|
||
| -- | Provides a `Functor` over the second argument of a `Profunctor`. | ||
| newtype Wrap p a b = Wrap (p a b) | ||
|
|
||
| derive instance newtypeWrap :: Newtype (Wrap p a b) _ | ||
| derive newtype instance eqWrap :: Eq (p a b) => Eq (Wrap p a b) | ||
| derive newtype instance ordWrap :: Ord (p a b) => Ord (Wrap p a b) | ||
|
|
||
| instance showWrap :: Show (p a b) => Show (Wrap p a b) where | ||
| show (Wrap x) = "(Wrap " <> show x <> ")" | ||
|
|
||
| instance functorWrap :: Profunctor p => Functor (Wrap p a) where | ||
| map f (Wrap a) = Wrap (rmap f a) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it's worth providing the adjoint, which constructs a profunctor from an invariant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I'd rather just remove
Invariant, but that's a separate, larger conversation 😄There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait! I just realised something, this is purescript-deprecated/purescript-monoid#34 if we provide
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any idea what the adjoint would look like? I just took a stab at it, but not really sure what I'm doing there and couldn't figure out how to implement
dimap.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found the previous discussion of this here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah! I remember now. Will add that too then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to give it a better name 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cojoinwas all I had, I'm not sure it's any better 😆Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Splitpossibly? Since we're trying to split the type argument into two.