Skip to content

hoistWithKey #39

@int-index

Description

@int-index
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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions