Skip to content

Pattern synonyms and Data instances #92

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 4 commits into from
Mar 26, 2023
Merged

Conversation

treeowl
Copy link
Collaborator

@treeowl treeowl commented Mar 17, 2023

  • Add some pattern synonyms.
  • Improve the Data instances to
    • Make the MinPQueue version incremental, like the MinQueue one.
    • Make all the instances respect the queue invariants.
  • Use the pattern synonyms to explain the Data instances.

Fixes #50.

@treeowl treeowl marked this pull request as draft March 17, 2023 03:24
@treeowl treeowl marked this pull request as ready for review March 17, 2023 04:20
@treeowl
Copy link
Collaborator Author

treeowl commented Mar 17, 2023

@konsumlamm I suspect we'll want similar pattern synonyms for max-queues, but do we want

(:>) :: Ord a => MaxQueue a -> a -> MaxQueue a

or

(<:) :: Ord a => a -> MaxQueue a -> MaxQueue a

I think the first option is clearer, since I think of the maximum as coming after the rest. But ergonomics will then be quite different between min-queues and max-queues, and I'm not sure how good that is. Hmmmmm....

Semi-separately: now that the Ord instance for Data.Ord.Down is decent, we should switch to it. We could then export MaxQueue and MaxPQueue concretely (with their constructors). Should they then use derived Data instances? I think that probably makes the most sense, but I'm not sure.

* Add some pattern synonyms.
* Improve the `Data` instances to
  - Make the `MinPQueue` version incremental, like the `MinQueue` one.
  - Make all the instances respect the queue invariants.
* Use the pattern synonyms to explain the `Data` instances.

Fixes lspitzner#50.
@treeowl treeowl force-pushed the patterns-data branch 2 times, most recently from 2c2df9a to 3496264 Compare March 17, 2023 04:41
@treeowl
Copy link
Collaborator Author

treeowl commented Mar 17, 2023

@konsumlamm In case you didn't notice, I was hoping for a review of this.

@konsumlamm
Copy link
Collaborator

@konsumlamm In case you didn't notice, I was hoping for a review of this.

I did notice, don't worry. It just takes some time to get into the issue again and I still have other things to do.

Copy link
Collaborator

@konsumlamm konsumlamm left a comment

Choose a reason for hiding this comment

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

Again, I don't know much about Data, so I'm just looking if things feel right.

@konsumlamm
Copy link
Collaborator

I'm reluctant about the pattern synonyms, as they're not O(1) (while standard patterns are) and people might expect them to be, unknowingly introducing a slowdown.

Is there a problem with keeping the Constrs as is?

@konsumlamm
Copy link
Collaborator

Btw, if you have time, could you take a look if #55 can be closed?

@treeowl
Copy link
Collaborator Author

treeowl commented Mar 17, 2023

I definitely like pattern synonyms for things that are at worst polylogarithmic. I think that's fine; I can document the bounds explicitly. I will update the PR to deal with the other issues you pointed out.

@treeowl
Copy link
Collaborator Author

treeowl commented Mar 17, 2023

@konsumlamm I think I've addressed all the issues. I would like to squash the commits rather than merging them intact.

@treeowl
Copy link
Collaborator Author

treeowl commented Mar 17, 2023

Is there a problem with keeping the Constrs as is?

I really don't like the inconsistency between the way the plain versions and Prio versions conceptualize their types. I also think it's much easier to "explain" the Data instances by reference to bidirectional patterns than by reference to plain functions (one of which doesn't even bother to exist). Since the Data instance for MinQueue was fairly broken from the jump, I'd be pretty surprised if anyone actually used them in any way that the proposed changes would break.

@konsumlamm
Copy link
Collaborator

Hmm, ok.

As for your question about :> vs <:, I don't really have an opinion on that. I'm fine with using :>, as that's similar to what Data.Sequence does.

Do you also want to improve the Data instances for max queues in this PR or leave that to a future PR?

@treeowl
Copy link
Collaborator Author

treeowl commented Mar 18, 2023

I don't want to make any decisions whatsoever about max queues in this PR. I'll open a new one for pattern synonyms for them.

@konsumlamm
Copy link
Collaborator

I would like to squash the commits rather than merging them intact.

That's what I always do anyway.

Co-authored-by: konsumlamm <[email protected]>
@treeowl
Copy link
Collaborator Author

treeowl commented Mar 26, 2023

Are you ready to approve?

@treeowl treeowl merged commit 5218be4 into lspitzner:master Mar 26, 2023
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.

Data instances are unsafe/wrong
2 participants