[Haskell-beginners] List -> Map -> List, to add duplicates?
amindfv at gmail.com
Tue Jun 7 03:43:13 CEST 2011
This seems like an inefficient way to do what I'm trying to do.
I'd really appreciate any suggestions or comments:
import qualified Data.Map as Map
data Currency = Dollar
deriving (Show, Eq, Ord) -- why ord?
withDups = [(30, Dollar), (-20, Street_Cred), (-2, Dollar), (30, XP),
(15, Peso), (30, XP)]
flipAssoc (a, b) = (b, a)
noDups = Map.fromListWith (+) (map flipAssoc withDups)
final = map flipAssoc $ Map.toList noDups
Thanks for your time!
More information about the Beginners