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

Need class for containers of elements that have their own keys #129

Open
AshleyYakeley opened this issue Apr 13, 2017 · 4 comments
Open

Comments

@AshleyYakeley
Copy link
Contributor

Currently, there's the IsMap class:

class (MonoTraversable map, SetContainer map) => IsMap map where
    type MapValue map
    lookup :: ContainerKey map -> map -> Maybe (MapValue map)
    insertMap :: ContainerKey map -> MapValue map -> map -> map
    -- etc.

In most (all?) instances of IsMap, we have Element map ~ (ContainerKey map, MapValue map), that is, there's some MapValue type that is "the element minus the key".

However, for some containers, there isn't a suitable MapValue type because the key cannot easily be removed from the Element type. Instead, we'd want a class that looks more like this:

class (MonoTraversable map, SetContainer map) => KeyContainer map where
    elementKey :: Element map -> ContainerKey map
    lookupElement :: ContainerKey map -> map -> Maybe (Element map)
    insertElement :: Element map -> map -> map
    -- etc.
@snoyberg
Copy link
Owner

snoyberg commented Apr 16, 2017 via email

@AshleyYakeley
Copy link
Contributor Author

I don't know if such types already exist, but:

  1. A hash-addressable store, where Element is ByteString and ContainerKey is a SHA-256 hash.
  2. An in-memory typed SQL table, where Element is a row, and ContainerKey is the primary key.

@snoyberg
Copy link
Owner

I'm sorry, but at this level of abstraction I'm having a really hard time understanding the request here.

@AshleyYakeley
Copy link
Contributor Author

Fair enough. Given that I don't actually know of any types in existing Haskell packages that would implement this and not IsMap, it might not be worth it.

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