[mercury-users] mode error
Fergus Henderson
fjh at cs.mu.OZ.AU
Fri Aug 9 23:26:43 AEST 2002
On 09-Aug-2002, Tom Schrijvers <Tom.Schrijvers at cs.kuleuven.ac.be> wrote:
> I get this strange mode error. The inferred and expected instantiatedness
> are identical, so I have no clue about what's wrong.
The compiler's error diagnosis here is definitely not good.
Basically the problem is that you need to module-qualify the functor
names in the inst definitions. Normally the compiler will infer the
right module qualifiers to use based on the type. However, in this
case your insts are used as the inst of a polymorphically-typed variable
(the first argument to eval/1) and the compiler therefore can't determine
the appropriate module qualifiers from the type.
Your mail has spurred me to improve the compiler's diagnostics.
I modified my local version of the compiler so that it expands out
insts in error messages. If the inst is recursive, then it just
prints out "..." once it gets to the recursive part.
With my modified version of the compiler, I get the following:
error.m:037: In clause for `m(in(error:val_closure((error:closure_list))), out((error:closure_list)))':
error.m:037: in argument 1 of call to predicate `error:eval/2':
error.m:037: mode error: variable `CCL' has instantiatedness `bound(error:val_closure((pred((free -> bound(error:list(ground, ...) ; (error:nil)))) is det)))',
error.m:037: expected instantiatedness was `bound(error:val_closure((pred((free -> bound(list(ground, bound(val_closure((pred(builtin:out(bound(list(ground, ...) ; nil))) is det)))) ; nil))) is det)))'.
Now, if you read this error message very carefully, you may notice
that "val_closure" occurs twice in the second inst -- but it is only
module-qualified the first time that it occurs! The expected inst
for the inner bit ("...") is "bound(val_closure)", but actual inst
for that part is "bound(error:val_closure)".
This error message is still admittedly not very clear,
but it is at least a small improvement ;-)
Here's a patch to your example program which allows it to compile.
--- error.m Fri Aug 9 22:52:49 2002
+++ error2.m Fri Aug 9 22:48:45 2002
@@ -14,7 +13,7 @@
---> val_closure(pred(X)).
:- inst val_closure(X)
- == bound( val_closure(pred(out(X)) is det) ).
+ == bound( error__val_closure(pred(out(X)) is det) ).
:- pred eval(val_closure(X),X).
%:- pred eval(val_closure(closure_list(X)),closure_list(X)).
@@ -27,8 +26,8 @@
; list(X,val_closure(closure_list(X))).
:- inst closure_list
- == bound( nil
- ; list(ground,val_closure(closure_list))
+ == bound( error__nil
+ ; error__list(ground,val_closure(closure_list))
).
:- pred m(val_closure(closure_list(X)),closure_list(X)).
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-users mailing list
post: mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the users
mailing list