Out of curiosity, what is the rationale for allowing programs to infer
certain types, but not for the (inferred) type to be declared?
On Fri, Feb 15, 2013 at 4:54 PM, David McBride toa...@gmail.com wrote:
sum' [] = [] -- returns a list of something the way you intended
sum' (x:xs) = x +
On 15 February 2013 19:22, Raphael Gaschignard dasur...@gmail.com wrote:
Out of curiosity, what is the rationale for allowing programs to infer
certain types, but not for the (inferred) type to be declared?
That's the type that's needed; the fact that you need an extension for
GHC to allow you
Note also that typeclasses are open, so ghc is not allowed to say that there is
no instance of Num for lists there; it will happily infer a type which requires
such an instance, and only when it needs to firm down to concrete types at some
point will it notice that there's no such instance in
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]
sum' [] = [] -- returns a list of something the way you intended
sum' (x:xs) = x + xum' xs -- you intended it not to return a list but it
could if you think about it.
The compiler says I think returns a list based on what I see so far, well
if you can add these together then the only way you