编辑代码

{-# LANGUAGE TransformListComp #-}

import GHC.Exts

type Ww = [(Int,Int)]
lim=1000000007

mul::Ww->Ww->Ww
mul w1 w2 m = [ (the (i+j)`mod`m,sum a*b`mod`lim)
    | (i,a)<-w1 , (j,b) <-w2
    ,the group by a using groupWith] 
pow::Ww->Int->Ww
pow a b=

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 output