@@ -187,7 +187,18 @@ prop> member @a (insert (x :: f a) tm) == True
187187
188188-}
189189insert :: forall a f . Typeable a => f a -> TypeRepMap f -> TypeRepMap f
190−insert = union . one
190+insert x m
191+ | size m == 0 = one x
192+ | otherwise = case cachedBinarySearch (typeFp @a) (fingerprintAs m) (fingerprintBs m) of
193+ Nothing -> union m $ one x
194+ Just i -> m {trAnys = changeAnyArr i (trAnys m)}
195+ where
196+ changeAnyArr :: Int -> Array Any -> Array Any
197+ changeAnyArr i trAs = runST $ do
198+ let n = sizeofArray trAs
199+ mutArr <- thawArray trAs 0 n
200+ writeArray mutArr i $ toAny x
201+ unsafeFreezeArray mutArr
191202{-# INLINE insert #-}
192203
193204-- Extract the kind of a type. We use it to work around lack of syntax for