Skip to content

Comments

Switch to indexed applicatives#11

Open
treeowl wants to merge 4 commits intomorphismtech:masterfrom
treeowl:indexed-applicative
Open

Switch to indexed applicatives#11
treeowl wants to merge 4 commits intomorphismtech:masterfrom
treeowl:indexed-applicative

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

@treeowl treeowl force-pushed the indexed-applicative branch from 8de300c to 82a2629 Compare August 5, 2021 19:56
treeowl added 2 commits August 5, 2021 15:59
* 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 treeowl force-pushed the indexed-applicative branch from a966178 to f216867 Compare August 5, 2021 21:26
@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