[Haskell-cafe] Data.Map.fromListWith

Paul Johnson paul at cogito.org.uk
Sat Dec 6 15:22:17 EST 2008


I've just been looking at the Data.Map function "fromListWith".  
According to the docs, it has the type:

*   fromListWith* :: Ord 
<http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Ord.html#t%3AOrd> 
k => (a -> a -> a) -> [(k, a)] -> Map 
<http://www.haskell.org/ghc/docs/latest/html/libraries/containers/Data-Map.html#t%3AMap> 
k a

I'd have thought that a better type would be

*   fromListWith* :: Ord 
<http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Ord.html#t%3AOrd> 
k => (a -> b -> b) -> [(k, a)] -> Map 
<http://www.haskell.org/ghc/docs/latest/html/libraries/containers/Data-Map.html#t%3AMap> 
k b

This wouldn't break any existing code, but would allow things like 
"fromListWith (:)" to do the Right Thing.

Would this be a sensible change (along with the other "with" functions 
in the module).

Paul.



More information about the Haskell-Cafe mailing list