@@ -220,15 +220,18 @@ hoistWithKey f (TypeRepMap as bs ans ks) = TypeRepMap as bs newAns ks
220220{-# INLINE hoistWithKey #-}
221221
222222-- | The union of two 'TypeRepMap's using a combining function.
223−unionWith :: (forall x. f x -> f x -> f x) -> TypeRepMap f -> TypeRepMap f -> TypeRepMap f
223+unionWith :: forall f. (forall x. Typeable x => f x -> f x -> f x) -> TypeRepMap f -> TypeRepMap f -> TypeRepMap f
224224unionWith f m1 m2 = fromTriples
225225 $ toTripleList
226226 $ Map.unionWith combine
227227 (fromTripleList $ toTriples m1)
228228 (fromTripleList $ toTriples m2)
229229 where
230+ f' :: forall x. TypeRep x -> f x -> f x -> f x
231+ f' tr = withTypeable tr f
232+
230233 combine :: (Any, Any) -> (Any, Any) -> (Any, Any)
231− combine (av, ak) (bv, _) = (toAny $ f (fromAny av) (fromAny bv), ak)
234+ combine (av, ak) (bv, _) = (toAny $ f' (fromAny ak) (fromAny av) (fromAny bv), ak)
232235
233236 fromTripleList :: Ord a => [(a, b, c)] -> Map.Map a (b, c)
234237 fromTripleList = Map.fromList . map (\(a, b, c) -> (a, (b, c)))