Skip to content

Rewrite rules for IntMap: intersectionWithKey/mapWithKey #1014

@ruifengx

Description

@ruifengx

I checked the source code and did not see these rules defined, but I imagine they should be beneficial for performance. Below are the rewrite rules I mean:

{-# RULES
"intersectionWith/mapWithKey/1"
  forall f g m n
  . intersectionWithKey f (mapWithKey g m) n
  = intersectionWithKey (\i a b -> f i (g i a) b) m n
"intersectionWith/mapWithKey/2"
  forall f g m n
  . intersectionWithKey f m (mapWithKey g n)
  = intersectionWithKey (\i a b -> f i a (g i b)) m n
#-}

In theory, they should be able to eliminate one intermediate IntMap, but I do not know enough of the internals of this library nor GHC optimisation passes to be sure.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions