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 typelevel salt #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add typelevel salt #1

wants to merge 1 commit into from

Conversation

jappeace
Copy link
Owner

@jappeace jappeace commented Sep 22, 2021

(trying to get github workflow to give me CI).

Real PR is here: haskell-unordered-containers#321

This allows clients to create custom salted hashmaps.
For backwards compatibility we use

```haskell
 -- backwards compatibility
type HashMap = HashMapT DefaultSalt
```

Then modify the functions to be free of salt if they can, for example insert:

```haskell
insert :: forall k v salt . (Eq k, Hashable k) => k -> v -> HashMapT salt k v -> HashMapT salt k v
insert k v m = insert' (hash salt k) k v m
  where
    salt = natVal (Proxy :: Proxy salt)
```

This allows the default HashMap with backwards compatibility,
but also any other HashMapT
I think this solves the issue with having different salts in
an intersect:

```haskell
intersection :: (Eq k, Hashable k) => HashMapT salt k v -> HashMapT salt k w -> HashMapT salt k v
```

Because salt is the same type variable for all arguments,
it's enforced to be the same.
Then you can also provide a function to resalt if the user ever ends
up with different salts and still wants to do an intersect.
(which results in a reconstruction of the hashmap).

See thread: haskell-unordered-containers#319

I know these libraries will at least fail with the changes because they have instances on `HashMap`,
which now need to be `HashMapT salt`:

quickcheck-instances-0.3.25.2.drv
semirings-0.6.drv
relude-0.7.0.0.drv
semigroupoids-5.3.5.drv

I did this by stubbing out unordered containers in a 100k loc codebase
to see what issues would come up in CI.
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.

1 participant