on main help sign in
Typeable elements in 'unionWith' (#67)
commit8744c9a5d1fc6c82075e29a29548ad51e631ee9a authorVladislav Zavialov <vlad.z.4096@gmail.com> dateSun 27 Jan 2019, 12:19 (8 years ago) parentabba60f
2 files changed+7−4
src/Data/TMap.hs+2−2 src/Data/TypeRepMap/Internal.hs+5−2
src/Data/TMap.hs+2−2
@@ -110,10 +110,10 @@ delete = F.delete @a @Identity
110110{-# INLINE delete #-}
111111
112112-- | 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
114114unionWith f = F.unionWith fId
115115 where
116− fId :: forall y . Identity y -> Identity y -> Identity y
116+ fId :: forall y . Typeable y => Identity y -> Identity y -> Identity y
117117 fId y1 y2 = Identity $ f (coerce y1) (coerce y2)
118118{-# INLINE unionWith #-}
119119
src/Data/TypeRepMap/Internal.hs+5−2
@@ -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)))