[Haskell-cafe] (+) on two lists ?

sheng chen kkchensheng at gmail.com
Fri Feb 15 08:33:25 CET 2013


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130214/5f1dda00/attachment.htm>


More information about the Haskell-Cafe mailing list