[Haskell-cafe] Extending the idea of a general Num to other types?

Ketil Malde ketil at ii.uib.no
Wed Sep 5 04:16:20 EDT 2007


On Wed, 2007-09-05 at 08:19 +0100, Simon Peyton-Jones wrote:

> | confusing for new users to have the compiler suggest pointless things
> | like declaring an instance of Num String or whatever. 

This also gets my vote for the
"Error-message-most-likely-to-be-unhelpful"-award.  IME, this often
arises from incorrect use of operators or wrong number of parameters,
not missing instances.

> It's difficult to make error messages helpful.  

Certainly. But better to err on the side of brevity.

>         when you come across a case where GHC produces an
>         unhelpful message, send it in, along with the program
>         that produced it,

Contents of test/error.hs:
    f x s = x + show s

Error message from GHCi:
    test/error.hs:2:8:
        No instance for (Num String)
          arising from use of `+' at test/error.hs:2:8-17
        Possible fix: add an instance declaration for (Num String)
        In the expression: x + (show s)
        In the definition of `f': f x s = x + (show s)

>         your suggestion for the error message you'd like to have seen.

Suggestion:
As is, with removal the "Possible fix", as it is often misleading (i.e.
here, the programmer clearly meant to use '++' and not '+'.  Perhaps
rephrase to something like "String is not an instance of Num"?  For a
newbie, it may not be clear that Num is the class and String is the
type.

-k






More information about the Haskell-Cafe mailing list