Skip to content
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

Switch to indexed applicatives #11

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

treeowl
Copy link

@treeowl treeowl commented Aug 5, 2021

  • The original qtraverse wasn't powerful enough to implement
    qfoldMapDefault. Using an indexed applicative makes it so.
  • Add qfoldMapDefault.
  • Adjust the type of traverse_ to match.
  • Remove the surprising QFunctor superclass of QFoldable.

Closes #10

* The original `qtraverse` wasn't powerful enough to implement
  `qfoldMapDefault`. Using an *indexed* applicative makes it so.
* Add `qfoldMapDefault`.
* Adjust the type of `traverse_` to match.
* Remove the surprising `QFunctor` superclass of `QFoldable`.

Closes morphismtech#10
Behold the power of `coerce`!
@treeowl
Copy link
Author

treeowl commented Aug 5, 2021

@echatav , here's my first little pull request. I have one or two more generalities to put in before I start porting things over from type-aligned (with some performance tweaks).

qtraverse f (ProductQ p q) = ProductQ p `imap` f q
instance QTraversable IQ where qtraverse f (IQ c) = IQ `imap` f c

newtype QReverse t c x y = QReverse {getQReverse :: t (OpQ c) y x}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks isomorphic to ApQ t c x y since (OpQ c) y x is isomorphic to c x y, so seems redundant

Copy link
Author

Choose a reason for hiding this comment

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

Redundant how? The basic idea is that it's possible to implement, say, a queue that enqueues on the left and dequeues on the right by wrapping the more usual version in QReverse. How do you propose to do it?

Copy link
Author

Choose a reason for hiding this comment

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

Okay, I guess it can always be done using IxBackwards directly. I just stole the idea from Data.Functor.Reverse. I guess it's at least a useful demonstration of IxBackwards?

Copy link
Collaborator

@echatav echatav Aug 6, 2021

Choose a reason for hiding this comment

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

I got the isomorphism wrong, it's not ApQ, it's OpQ (t (OpQ c)). It's interesting because you could use it in reversePath to change the signature from

reversePath :: (QFoldable c, CFree path) => c p x y -> path (OpQ p) y x

to

reversePath :: (QFoldable c, CFree path) => c p x y -> ReverseQ path p x y

I haven't given thought to how to port queues since I never needed them :-/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use indexed applicatives
2 participants