[mercury-users] Incomprehensible error output, even with -E.

Julian Fondren ayrnieu at gmail.com
Thu Feb 2 17:04:10 AEDT 2012


On Wed, Feb 1, 2012 at 11:13 PM, Michael Richter <ttmrichter at gmail.com> wrote:

> Hmmm....  Seems to be a clash of variable name scopes.  Maybe a some?
>
>     A = (func(X) = Y :-
>             some [X,Y] (
>                 B = (func(X) = Y :-
>                         Y = X * 2
>                     )
>             ),
>             Y = apply(B, X)
>         ),
>
> Eh.... no.  That tosses up lots as well:
>

The error:

> junk.m:019: In clause for `main(di, uo)':
> junk.m:019:   mode error in conjunction. The next 3 error messages indicate
> junk.m:019:   possible causes of this error.

possible cause #1:

> junk.m:021:   In clause for `main(di, uo)':
> junk.m:021:   mode error: variable `Y' has instantiatedness `free',
> junk.m:021:   expected instantiatedness for non-local variables of lambda
> goals
> junk.m:021:   is `ground'.

possible cause #2:

> junk.m:025:   In clause for `main(di, uo)':
> junk.m:025:   in argument 1 (i.e. the function term) of higher-order
> function
> junk.m:025:   call:
> junk.m:025:   mode error: variable `B' has instantiatedness `free',
> junk.m:025:   expecting higher-order func inst (of arity 1).

possible cause #3:

> junk.m:019:   In clause for `main(di, uo)':
> junk.m:019:   in argument 1 of clause head:
> junk.m:019:   mode error in unification of `V_11' and `Y'.
> junk.m:019:   Variable `V_11' has instantiatedness `free',
> junk.m:019:   variable `Y' has instantiatedness `free'.

> And at this point I'm lost.  How does X have overlapping scope when I've
> explicitly built a new scope for the second X?

That's a warning, not an error.  The error is with Y, and the problem I'd
guess is a bug with 'some' and mode analysis.  Taking that out, and
reversing the order (which changes nothing, in Mercury), you have

  Y = Z  % Z is ground, so Y is also ground.
  B = (func(X) = Y :- Y = X * 2),  % X is ground; Y is of course
free--wait!  No it isn't!

> Why am I wrestling
> so much with Mercury to do the same?  What am I missing?

You had a newbie syntax error and now you have a compiler bug.
The error messages in both cases are mysterious.  The syntax is
a bit of a chore even when you get it right.  But you can certainly

  1. use different names for different variables; and

  2. prefer named/moded/typed definitions to anonymous ones.

Exercising #1:

:- module junk.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
:- import_module int, string, list.

main(!IO) :-
	A = (func(X) = Y :-
		B = (func(X) = R :- R = X * 2),
		Y = apply(B, X)
	),
	io.format("A(2) = %d\n", [i(A(2))], !IO).

Exercising #2:

:- module junk2.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
:- import_module int, string, list.

main(!IO) :-
	io.format("A(2) = %d\n", [i(mystery(2))], !IO).

:- func double(int) = int.
double(X) = X * 2.

% what's the point of this?
:- func mystery(int) = int.
mystery(X) = R :-
	R = apply(B, X),
	B = double.

--------------------------------------------------------------------------
mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the users mailing list