[m-users.] type error message for polymorphic predicates

Matthias Güdemann matthias.guedemann at googlemail.com
Mon Jan 19 23:00:08 AEDT 2015


Hi,

I came across an error message which could be clearer in my opinion.

The following program:

╭────
│:- module test.
│:- interface.
│:- import_module io.
│:- pred main(io::di, io::uo) is det.
│:- implementation.
│:- import_module int.
│:- pred test(float::in, float::in) is semidet.
│test(A, B) :-  A < B.
│main(!IO) :-
│    ( test(1.0, 2.0) -> print("ok\n", !IO); print("nok\n", !IO)).
╰────

gives the message (mmc -E):

╭────
│Making Mercury/cs/test.c
│test.m:008: In clause for predicate `test'/2:
│test.m:008:   in argument 1 of call to predicate `<'/2:
│test.m:008:   type error: variable `A' has type `float',
│test.m:008:   expected type was `int'.
│test.m:008:   The partial type assignment was:
│test.m:008:     A_3: float
│test.m:008:     B_4: float
│test.m:008: In clause for predicate `test'/2:
│test.m:008:   in argument 2 of call to predicate `<'/2:
│test.m:008:   type error: variable `B' has type `float',
│test.m:008:   expected type was `int'.
│test.m:008:   The partial type assignment was:
│test.m:008:     A_3: float
│test.m:008:     B_4: float
│** Error making `Mercury/cs/test.c'.
╰────

In my opinion, it would be better to warn about the undeclared type
float instead. The declaration of the predicate states that floats are
expected and not integers.

Best regards
Matthias



More information about the users mailing list