Reg writes:
> This little problem raises two challenges for compiler developers:
> (a) improving diagnostic messages (a perennial issue), and (b) (semi)
> automating error correction.  In this case the diagnostic message
> is pretty good, except that is doesn't indicate where the IO term
> is or where the [] term is that doesn't match.  This is the critical
> piece of information Malcolm added to explain the problem.

Some Haskell systems are better than others in giving good diagnostics,
and even then, which compiler gives a better report sometimes may
depend on the particular error.

Hugs takes the approach of textually identifying the sub-expression in
question.  Nhc gives line/character source references.  I have found
both of these styles useful.

Just out of interest, for the original problem, nhc98 tells me

>         Error after type deriving/checking:
> Type error type clash between Prelude.IO and Prelude.[]
> when trying to apply function at 3:33 to its 2:nd argument at 3:37.

which tells me that >>= (at line 3 col 33) expected an IO type for
`filter' (at 3:37), but actually got a [] type.  In this case it is
exactly what you wanted to know (but I'm not claiming nhc will always
be this helpful!)

Thank goodness for Haskell 98 I say  Do you really want to know what
nhc13 (Haskell 1.3) would have said?

> Error: The class Prelude.MonadZero has no instance for the type Prelude.IO.
> Possible sources for the problem are:3:37

Bleagh!

Regards,
    Malcolm


Reply via email to