
3 Mar
2016
3 Mar
'16
12:23 p.m.
Does anybody know why for fromListWith, the arguments to the combining function seem flipped?
import Data.Map fromListWith (++) [('a',[1]),('a',[2])]
fromList [('a',[2,1])] I often use it to group things by some key, e.g. postsByUserId :: Map Int [Int] postsByUserId = fromListWith (++) [ (userId, [postId]) | (userId, postId) <- posts ] and regularly get tricked by the postIds being reversed in the result. This is especially unintuitive to me since:
foldl (++) [] [[1],[2]] [1,2] foldr (++) [] [[1],[2]] [1,2]
Any ideas?