Hi,

I was puzzled by the following little program.

sum' [] = []
sum' (x:xs) = x + sum' xs

I thought the GHC type checker will report a type error. However, the type
checker accepts this program and gives the type

Num [a] => [[a]] -> [a]

When I add type annotation to the program

sum' :: Num [a] => [[a]] -> [a]
sum' [] = []
sum' (x:xs) = x + sum' xs

The GHC asks me to add FlexibleContexts language extension.

I would appreciate explanation on this issue.

Thanks,
Sheng
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to