@@ -3312,7 +3312,19 @@ foldlFB = foldlWithKey
3312
3312
3313
3313
fromAscList :: Eq k => [(k ,a )] -> Map k a
3314
3314
fromAscList xs
3315
- = fromAscListWithKey (\ _ x _ -> x) xs
3315
+ = fromDistinctAscList (combineEq xs)
3316
+ where
3317
+ -- [combineEq f xs] combines equal elements with function [f] in an ordered list [xs]
3318
+ combineEq xs'
3319
+ = case xs' of
3320
+ [] -> []
3321
+ [x] -> [x]
3322
+ (x: xx) -> combineEq' x xx
3323
+
3324
+ combineEq' z [] = [z]
3325
+ combineEq' z@ (kz,zz) (x@ (kx,xx): xs')
3326
+ | kx== kz = combineEq' (kx,xx) xs'
3327
+ | otherwise = z: combineEq' x xs'
3316
3328
#if __GLASGOW_HASKELL__
3317
3329
{-# INLINABLE fromAscList #-}
3318
3330
#endif
@@ -3326,8 +3338,19 @@ fromAscList xs
3326
3338
-- > valid (fromDescList [(5,"a"), (3,"b"), (5,"b")]) == False
3327
3339
3328
3340
fromDescList :: Eq k => [(k ,a )] -> Map k a
3329
- fromDescList xs
3330
- = fromDescListWithKey (\ _ x _ -> x) xs
3341
+ fromDescList xs = fromDistinctDescList (combineEq xs)
3342
+ where
3343
+ -- [combineEq f xs] combines equal elements with function [f] in an ordered list [xs]
3344
+ combineEq xs'
3345
+ = case xs' of
3346
+ [] -> []
3347
+ [x] -> [x]
3348
+ (x: xx) -> combineEq' x xx
3349
+
3350
+ combineEq' z [] = [z]
3351
+ combineEq' z@ (kz,zz) (x@ (kx,xx): xs')
3352
+ | kx== kz = combineEq' (kx,xx) xs'
3353
+ | otherwise = z: combineEq' x xs'
3331
3354
#if __GLASGOW_HASKELL__
3332
3355
{-# INLINABLE fromDescList #-}
3333
3356
#endif
0 commit comments