+deriveMap ∷ Q Cxt → Q Type → Q Exp → Q Exp → Q Dec
+deriveMap c ty wrap unwrap
+ = do names ← methodNames ''Map
+ instanceD c ty $ concatMap (pointfreeMethod exp) names
+ where
+ exp ∷ Name → Q Exp
+ exp name
+ | name ≡ 'delete
+ = [| ($wrap ∘) ∘ (∘ $unwrap) ∘ delete |]
+ | name ≡ 'member
+ = [| (∘ $unwrap) ∘ member |]
+ | name ≡ 'union
+ = [| ($wrap ∘) ∘ (∘ $unwrap) ∘ union ∘ $unwrap |]
+ | name ≡ 'intersection
+ = [| ($wrap ∘) ∘ (∘ $unwrap) ∘ intersection ∘ $unwrap |]
+ | name ≡ 'difference
+ = [| ($wrap ∘) ∘ (∘ $unwrap) ∘ difference ∘ $unwrap |]
+ | name ≡ 'isSubset
+ = [| (∘ $unwrap) ∘ isSubset ∘ $unwrap |]
+ | name ≡ 'isProperSubset
+ = [| (∘ $unwrap) ∘ isProperSubset ∘ $unwrap |]
+ | name ≡ 'lookup
+ = [| (∘ $unwrap) ∘ lookup |]
+ | name ≡ 'alter
+ = [| (($wrap ∘) ∘) ∘ flip flip $unwrap ∘ ((∘) ∘) ∘ alter |]
+ | name ≡ 'insertWith
+ = [| ((($wrap ∘) ∘) ∘) ∘ flip flip $unwrap ∘ ((flip ∘ ((∘) ∘)) ∘) ∘ insertWith |]
+ | name ≡ 'fromFoldableWith
+ = [| ($wrap ∘) ∘ fromFoldableWith |]
+ | name ≡ 'foldGroups
+ = [| (($wrap ∘) ∘) ∘ foldGroups |]
+ | name ≡ 'mapWithKey
+ = [| ($wrap ∘) ∘ (∘ $unwrap) ∘ mapWithKey |]
+ | name ≡ 'unionWith
+ = [| (($wrap ∘) ∘) ∘ flip flip $unwrap ∘ ((∘) ∘) ∘ (∘ $unwrap) ∘ unionWith |]
+ | name ≡ 'intersectionWith
+ = [| (($wrap ∘) ∘) ∘ flip flip $unwrap ∘ ((∘) ∘) ∘ (∘ $unwrap) ∘ intersectionWith |]
+ | name ≡ 'differenceWith
+ = [| (($wrap ∘) ∘) ∘ flip flip $unwrap ∘ ((∘) ∘) ∘ (∘ $unwrap) ∘ differenceWith |]
+ | name ≡ 'isSubmapBy
+ = [| flip flip $unwrap ∘ ((∘) ∘) ∘ (∘ $unwrap) ∘ isSubmapBy |]
+ | name ≡ 'isProperSubmapBy
+ = [| flip flip $unwrap ∘ ((∘) ∘) ∘ (∘ $unwrap) ∘ isProperSubmapBy |]
+ | otherwise
+ = fail $ "deriveMap: unknown method: " ⧺ pprint name
+