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

hoistWithKey #39

Closed
int-index opened this issue Jul 11, 2018 · 1 comment
Closed

hoistWithKey #39

int-index opened this issue Jul 11, 2018 · 1 comment
Assignees

Comments

@int-index
Copy link
Collaborator

hoistWithKey :: (forall x. Typeable x => f x -> g x) -> TypeRepMap f -> TypeRepMap g

Adding this function will require adding another vector that will store TypeReps:

data TypeRepMap (f :: k -> Type) =
  TypeRepMap
    { fingerprintAs :: {-# UNPACK #-} !(PrimArray Word64) -- ^ first components of key fingerprints
    , fingerprintBs :: {-# UNPACK #-} !(PrimArray Word64) -- ^ second components of key fingerprints
    , anys          :: {-# UNPACK #-} !(Array Any)        -- ^ values stored in the map
    , keys          :: {-# UNPACK #-} !(Array Any)        -- ^ typerep keys
}

In hoistWithKey we can access a corresponding element in keys, cast it to TypeRep a and then apply https://hackage.haskell.org/package/base-4.11.1.0/docs/Type-Reflection.html#v:withTypeable to get the Typeable instance.

I'm hoping it won't affect the performance of lookups: the cachedBinarySearch function will stay unchanged.

Implementation plan:

  1. add the keys field, check that the benchmarks show no change
  2. implement hoistWithKey. it should be probably available only on 8.2+ because it relies on the new TypeRep for withTypeable
@int-index
Copy link
Collaborator Author

Having this function will also make it possible to write a useful map for TMap:

map :: (forall a. Typeable a => a -> a) -> TMap -> TMap

which is an instantiation of hoistWithKey to Identity

@vrom911 vrom911 self-assigned this Jul 27, 2018
vrom911 pushed a commit that referenced this issue Jul 27, 2018
chshersh pushed a commit that referenced this issue Jul 28, 2018
* [#39] Add hoistWithKey and map for TMap

* Use coerce instead of fmap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants