Skip to content

Rewrite rules for Data.Map.Merge.Lazy interface #3

@endgame

Description

@endgame

There are some obvious specialisations for Data.Semialign.Diff.diff and Data.Semialign.Diff.diffNoEq, using the high-perfomance interface in Data.Map.Merge.Lazy:

diffMap
  :: ( AsEmpty p
     , At p
     , Eq a
     , Index p ~ k
     , IxValue p ~ Maybe a
     , Ord k
     )
  => Map k a
  -> Map k a
  -> p

diffMapToMap :: (Ord k, Eq a) => Map k a -> Map k a -> Map k (Maybe a)

And some rewrite rules:

{-# NOINLINE [0] diff #-}
{-# RULES

"diff/MapToMap" [2]
  forall (m :: Ord k => Map k a) n.
  diff m n = diffMapToMap m n

"diff/Map" [1]
  forall (m :: Ord k => Map k a) n.
  diff m n = diffMap m n

#-}

Using inspection-testing and this code:

test :: Map String (Maybe Int)
test = diff (Map.fromList [("a", 1), ("b", 2)]) (Map.fromList [("a", 3), ("c", 4)])

$(inspect $ coreOf 'test)

It appears that neither rewrite rule is firing.

There are likely similar rules available for patching maps using maps, if I can get them to fire.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions