
19 Jun
2006
19 Jun
'06
1:13 a.m.
Hello, I want to creat a function sumList as below examples: sumList [("s1",2),("s2",4),("s3",3),("s4",2)] = ("#", 1/2 + 1/4 + 1/3 + 1/2) sumList [("s1",2),("s2",4),("s3",3) = ("#", 1/2 + 1/4 + 1/3) I attempted it as following: sumList :: (Fractional a) => [(String,a)] -> (String, a) sumList [] = ??? sumList (x:xs) = ("#", 1/(snd x) + 1/snd(sumList xs)) I know this function cannot give the correct answer (even if I define sumList []), but I did not find the right way. If anyone can give me a suggestion, I really appereciate for that. Thanks. S.