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

Add a bag type, and Bag structure, to represent unordered collections with duplicates allowed #235

Open
julianhyde opened this issue Dec 14, 2024 · 0 comments

Comments

@julianhyde
Copy link
Collaborator

The built-in list type represents an ordered collection with duplicates allowed; in this change, we add a bag type that also allows duplicates but has no guaranteed order. (See discussion #232.)

This means that, given a bag and a list with the same N elements, the list contains more information, because it has remembered which of the N! orderings of the elements has occurred. Converting from a list to a bag is therefore lossy. But there is a bijection between 'a list and ('a * int) bag provided that the int ordinals are unique.

The Bag structure has analogous operations to the standard List structure, except for nth, take, drop, rev.

We add mapi to List (based on Vector.mapi).

julianhyde added a commit to julianhyde/morel that referenced this issue Dec 14, 2024
…dered collections with duplicates allowed

The built-in `list` type represents an ordered collection with duplicates allowed; in this change, we add a `bag` type that also allows duplicates but has no guaranteed order.

This means that, given a bag and a list with the same N elements, the list contains more information, because it has remembered which of the N! orderings of the elements has occurred. Converting from a list to a bag is therefore lossy. But there is a bijection between 'a list and ('a * int) bag provided that the int ordinals are unique.

The Bag structure has analogous operations to the standard List structure, except for nth, take, drop, rev.

We add mapi to List (based on Vector.mapi).

Fixes hydromatic#235
julianhyde added a commit to julianhyde/morel that referenced this issue Dec 27, 2024
…dered collections with duplicates allowed

The built-in `list` type represents an ordered collection with duplicates allowed; in this change, we add a `bag` type that also allows duplicates but has no guaranteed order.

This means that, given a bag and a list with the same N elements, the list contains more information, because it has remembered which of the N! orderings of the elements has occurred. Converting from a list to a bag is therefore lossy. But there is a bijection between 'a list and ('a * int) bag provided that the int ordinals are unique.

The Bag structure has analogous operations to the standard List structure, except for nth, take, drop, rev.

We add mapi to List (based on Vector.mapi).

Fixes hydromatic#235
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

No branches or pull requests

1 participant