编辑代码

-- {-# LANGUAGE TransformListComp #-}

import GHC.Exts

type Ww = [(Int,Int)]
lim=1000000007
mul::Ww->Ww->Int->Ww
mul w1 w2 m = map (\x->( (fst.head) x,(sum.snd.unzip) x ) ) ( groupWith fst res )
              -- map (fst.head,sum.snd.unzip) ( groupWith fst res )
    where res=[( (i+j)`mod`m ,a*b )|(i,a)<-w1,(j,b)<-w2]

{-
input = [("Norte",4,23,20),("Norte",4,3,2),("Norte",4,4,5),("Centro",6,0,0),("Sul",3,0,0)]

output = [(the a, the b, sum c, sum d)
    | (a, b, c, d) <- input
    , then group by a using groupWith]
-}
main = print $ mul [(0,1),(1,2),(2,3)] [(0,4),(1,5),(2,6)] 3