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

Wrapped sets and maps #171

Open
treeowl opened this issue Oct 17, 2018 · 8 comments
Open

Wrapped sets and maps #171

treeowl opened this issue Oct 17, 2018 · 8 comments

Comments

@treeowl
Copy link

treeowl commented Oct 17, 2018

A map from elements of type k to () can be viewed as a set. Indeed, this is how Data.HashSet works. Less usefully, I imagine, a set of elements of type k can also be viewed as a map from elements of type k to (). Should we offer newtype wrappers implementing this correspondence?

@snoyberg
Copy link
Owner

What would these look like? What would be the advantage for the user?

@treeowl
Copy link
Author

treeowl commented Oct 18, 2018

I'm not sure what you mean about what they'd look like. For the wrapped map case, the purpose would be to let libraries depending on this one magically turn their map implementations into set implementations. Applications the other way are definitely not as obvious.

@snoyberg
Copy link
Owner

I mean what are you proposing as the newtype wrapper here? I'm not sure what practically benefit you're going for here. Is the idea to get to elide definitions of data types like HashSet completely, and just rely on a newtype wrapper?

@treeowl
Copy link
Author

treeowl commented Oct 18, 2018

Sounds about right.

newtype WrappedMap m = WrappedMap {unwrappedMap :: m}
newtype HashSet a = HashSet (WrappedMap (HashMap a ()))
  deriving ({- all the instances -})

@snoyberg
Copy link
Owner

What's the purpose of the newtype WrappedMap here?

@treeowl
Copy link
Author

treeowl commented Oct 18, 2018

It's just a target for GND. The relationship between a set of a and a map from a to () has to be implemented somewhere... There's no (inherent) need to implement it separately and by hand for each map type.

@treeowl
Copy link
Author

treeowl commented Oct 18, 2018

Obviously unordered-containers will not be incurring a mono-traversable dependency, but I feel like this wrapper should exist as a matter of principle.

@snoyberg
Copy link
Owner

Arguments on principle aren't really too interesting to me, I'm sorry. I'm much more interested in code being useful in some kind of real-world case.

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

2 participants