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

Hoopl collection classes could use enummapset? #53

Open
hth313 opened this issue Oct 31, 2020 · 6 comments
Open

Hoopl collection classes could use enummapset? #53

hth313 opened this issue Oct 31, 2020 · 6 comments

Comments

@hth313
Copy link

hth313 commented Oct 31, 2020

I have found myself using https://hackage.haskell.org/package/enummapset a lot in my code. It provides wrappers around IntSet/IntMap that uses Enum rather than Int, which allows for better type safety.

Now I am doing more work with Hoopl in my project and it lacks certain useful functions from IntMap. I am looking at restrictKeys at the moment. I am trying to wrap my head around how to implement it, but I also realize that in some way this collection code in Hoopl is just the same thing as is also provided by enummapset. I was thinking that maybe it would better to migrate the code in Hoopl to make use of enummapset rather than rolling its own duplicate that tends to be out of date (I have added some missing functions before).

I wonder what the maintainer and people using Hoopl think about this?

@mlite
Copy link
Contributor

mlite commented Nov 1, 2020 via email

@simonpj
Copy link

simonpj commented Nov 2, 2020

If it's just a question of boilerplate newtype wrappers, I'd be inclined to copy the necessary ones into hoopl, rather than take a dependency on another library. hoopl probably only uses half a dozen such functions.

Let's see what the hoopl maintainers say.

As to performance, I think that only newtype wrappers are involved, so perf impact should be zero. But worth checking anyway.

@hth313
Copy link
Author

hth313 commented Nov 2, 2020

I added some missing functions in the past, but restricyKeys requires connecting the IsSet with the IsMap somehow, and I have yet to figure out how to do it. I tried with fundeps, but I am not a type wizard by any means, so I am kind of stuck going in that direction.

@mlite
Copy link
Contributor

mlite commented Nov 2, 2020 via email

@hth313
Copy link
Author

hth313 commented Nov 2, 2020

I support reimplementing the newtype wrappers in hoopl.

So, how do you make it work?

src/Compiler/Hoopl/Label.hs:106:27: error:
    • Couldn't match expected type ‘set’ with actual type ‘LabelSet’
      ‘set’ is a rigid type variable bound by
        the type signature for:
          mapRestrictKeys :: forall set a.
                             IsSet set =>
                             LabelMap a -> set -> LabelMap a
        at src/Compiler/Hoopl/Label.hs:106:3-17
    • In the pattern: LS s
      In an equation for ‘mapRestrictKeys’:
          mapRestrictKeys (LM m) (LS s) = LM (restrictKeys m s)
      In the instance declaration for ‘IsMap LabelMap’
    • Relevant bindings include
        mapRestrictKeys :: LabelMap a -> set -> LabelMap a
          (bound at src/Compiler/Hoopl/Label.hs:106:3)

@mlite
Copy link
Contributor

mlite commented Nov 3, 2020 via email

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

3 participants