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

Julien Fischer jfischer at opturion.com
Tue Jan 20 13:05:13 AEDT 2015


Hi Matthias,

On Mon, 19 Jan 2015, Matthias Güdemann wrote:

> 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 type float is _not_ undeclared.  The primive types int, string,
float and character are builtin and always visible.  This is the case
even if the int, string, float and char modules respectively are not
imported.  The problem here is that the module 'float' (and the
declaration of float.(<)/2 it contains) is not imported.

Cheers,
Julien.


More information about the users mailing list