on main help sign in
Typeable elements in 'unionWith' (#67)
8744c9aVladislav Zavialov
src/Data/TMap.hs+2−2
@@ -110,10 +110,10 @@ delete = F.delete @a @Identity
110{-# INLINE delete #-}
110{-# INLINE delete #-}
111
111
112-- | The union of two 'TMap's using a combining function.
112-- | The union of two 'TMap's using a combining function.
113−unionWith :: (forall x. x -> x -> x) -> TMap -> TMap -> TMap
113+unionWith :: (forall x. Typeable x => x -> x -> x) -> TMap -> TMap -> TMap
114unionWith f = F.unionWith fId
114unionWith f = F.unionWith fId
115 where
115 where
116− fId :: forall y . Identity y -> Identity y -> Identity y
116+ fId :: forall y . Typeable y => Identity y -> Identity y -> Identity y
117 fId y1 y2 = Identity $ f (coerce y1) (coerce y2)
117 fId y1 y2 = Identity $ f (coerce y1) (coerce y2)
118{-# INLINE unionWith #-}
118{-# INLINE unionWith #-}
119
119
src/Data/TypeRepMap/Internal.hs+5−2
@@ -220,15 +220,18 @@ hoistWithKey f (TypeRepMap as bs ans ks) = TypeRepMap as bs newAns ks
220{-# INLINE hoistWithKey #-}
220{-# INLINE hoistWithKey #-}
221
221
222-- | The union of two 'TypeRepMap's using a combining function.
222-- | 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
224unionWith f m1 m2 = fromTriples
224unionWith f m1 m2 = fromTriples
225 $ toTripleList
225 $ toTripleList
226 $ Map.unionWith combine
226 $ Map.unionWith combine
227 (fromTripleList $ toTriples m1)
227 (fromTripleList $ toTriples m1)
228 (fromTripleList $ toTriples m2)
228 (fromTripleList $ toTriples m2)
229 where
229 where
230+ f' :: forall x. TypeRep x -> f x -> f x -> f x
231+ f' tr = withTypeable tr f
232+
230 combine :: (Any, Any) -> (Any, Any) -> (Any, Any)
233 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)
232
235
233 fromTripleList :: Ord a => [(a, b, c)] -> Map.Map a (b, c)
236 fromTripleList :: Ord a => [(a, b, c)] -> Map.Map a (b, c)
234 fromTripleList = Map.fromList . map (\(a, b, c) -> (a, (b, c)))
237 fromTripleList = Map.fromList . map (\(a, b, c) -> (a, (b, c)))