[mercury-users] constrained polymorphic mode error
Tom Schrijvers
Tom.Schrijvers at cs.kuleuven.ac.be
Fri Aug 16 22:40:28 AEST 2002
On Mon, 12 Aug 2002, David Overton wrote:
> On Fri, Aug 09, 2002 at 08:14:18PM +0200, Tom Schrijvers wrote:
> I've just committed a fix for this bug which should appear in the next
> ROTD.
Yes, thank you, the bug is fixed in the rotd of 08-15-2002.
I have now run into another error message concerning contrained
polymorphic modes in this unstable rotd.
I think the real error is the one saying that 'argument 1 became too
instantiated'. To me it looks similar to the previous bug, i.e. the
expected instantiatedness is more general than the inferred one.
Do you think this is a bug in the compiler or did I do something wrong?
Thanks for all the help,
Tom
Here's the error message:
[tom at ender closure]$ mmc closure2.m -E
closure2.m:067: In clause for `map(in(closure2:fun_closure((X =< ground),
(Y =< ground))), in(closure2:val_closure(closure2:closure_list((X =<
ground)))), out(closure2:val_closure(closure2:closure_list((Y =<
ground)))))':
closure2.m:067: mode error in conjunction. The next 4 error messages
closure2.m:067: indicate possible causes of this error.
closure2.m:066: In clause for `map(in(closure2:fun_closure((X =< ground),
(Y =< ground))), in(closure2:val_closure(closure2:closure_list((X =<
ground)))), out(closure2:val_closure(closure2:closure_list((Y =<
ground)))))':
closure2.m:066: mode error in unification of `NCTC' and
`closure2:val_closure(V_12)'.
closure2.m:066: Variable `NCTC' has instantiatedness `free',
closure2.m:066: term `closure2:val_closure(V_12)'
closure2.m:066: has instantiatedness `closure2:val_closure(free)'.
closure2.m:066: In clause for `map(in(closure2:fun_closure((X =< ground),
(Y =< ground))), in(closure2:val_closure(closure2:closure_list((X =<
ground)))), out(closure2:val_closure(closure2:closure_list((Y =<
ground)))))':
closure2.m:066: mode error: argument 1 became too instantiated.
closure2.m:066: Final instantiatedness of `V_20' was
`bound(closure2:list((Y =< ground), bound(closure2:val_closure((pred((free
-> bound(closure2:list((Y =< ground),
bound(closure2:val_closure((pred((free -> ...)) is det)))) ;
(closure2:nil)))) is
det)))) ; (closure2:nil))',
closure2.m:066: expected final instantiatedness was `(X =< ground)'.
closure2.m:067: In clause for `map(in(closure2:fun_closure((X =< ground),
(Y =< ground))), in(closure2:val_closure(closure2:closure_list((X =<
ground)))), out(closure2:val_closure(closure2:closure_list((Y =<
ground)))))':
closure2.m:067: mode error in unification of `RCL' and
`closure2:val_closure(V_14)'.
closure2.m:067: Variable `RCL' has instantiatedness `free',
closure2.m:067: term `closure2:val_closure(V_14)'
closure2.m:067: has instantiatedness `closure2:val_closure(free)'.
closure2.m:067: In clause for `map(in(closure2:fun_closure((X =< ground),
(Y =< ground))), in(closure2:val_closure(closure2:closure_list((X =<
ground)))), out(closure2:val_closure(closure2:closure_list((Y =<
ground)))))':
closure2.m:067: in argument 1 of functor `val_closure/1':
closure2.m:067: mode error: variable `NCTC' has instantiatedness `free',
closure2.m:067: expected instantiatedness for non-local variables
closure2.m:067: of lambda goals is `ground'.
(maybe now that you are introducing constrained polymorphic modes
you could changes this last error message to:
expected instantiatedness for non-local variables
of lambda goals is `X =< ground'.
;)
)
and here's the code:
:- module closure2.
:- interface.
:- import_module io.
:- type fun_closure(X,Y)
---> fun_closure(pred(X,Y)).
:- type val_closure(X)
---> val_closure(pred(X)).
:- type closure_list(X)
---> nil
; list(X,val_closure(closure2__closure_list(X))).
:- inst fun_closure(X,Y)
== bound( closure2__fun_closure(pred(in(X),out(Y)) is det) ).
:- inst val_closure(X)
== bound( closure2__val_closure(pred(out(X)) is det) ).
:- inst closure_list(X)
== bound( closure2__nil
; closure2__list(X,closure2__val_closure(closure2__closure_list(X)))
).
:- pred main(io__state,io__state).
:- mode main(di,uo) is det.
:- implementation.
:- import_module int.
:- pred eval(val_closure(X),X).
:- mode eval(in(val_closure(X =< ground)),out(X =< ground)) is det.
eval(val_closure(P),X) :-
call(P,X).
:- pred eval2(pred(val_closure(X)),X).
:- mode eval2(pred(out(val_closure(X =< ground))) is det,out(X =< ground)) is det.
eval2(P,R) :-
call(P,X),
eval(X,R).
:- pred apply(fun_closure(X,Y),X,Y).
:- mode apply(in(fun_closure(X =< ground,Y =< ground)),in(X =< ground),out(Y =< ground)) is det.
apply(fun_closure(P),X,Y) :-
call(P,X,Y).
:- pred map(fun_closure(X,Y),
val_closure(closure_list(X)),
val_closure(closure_list(Y))).
:- mode map(in(fun_closure(X =< ground,Y =< ground)),
in(val_closure(closure_list(X =< ground))),
out(val_closure(closure_list(Y =< ground)))) is det.
map(FC,CCL,RCL) :-
eval(CCL,CL),
( CL = list(H,CTC) ->
apply(FC,H,NH),
NCTC = val_closure(eval2(map(FC,CTC))),
RCL = val_closure(closure_list_list(NH,NCTC))
;
RCL = val_closure(closure_list_nil)
).
:- pred closure_list_nil(closure_list(X)).
:- mode closure_list_nil(out(closure_list(X))) is det.
closure_list_nil(nil).
:- pred closure_list_list(X,val_closure(closure_list(X)),closure_list(X)).
:- mode closure_list_list(in(X =< ground),
in(val_closure(closure_list(X =< ground))),
out(closure_list(X =< ground))) is det.
closure_list_list(H,CT,list(H,CT)).
:- pred twice(int::in,int::out) is det.
twice(X,Y) :-
Y is X * 2.
:- pred test(val_closure(closure_list(int))).
:- mode test(out(val_closure(closure_list(ground)))) is det.
test(R) :-
P = (pred(N::out(closure_list(ground))) is det :- N = nil),
map(fun_closure(twice),val_closure(P),R).
main -->
{test(R)},
io__write(R),
io__nl
.
--------------------------------------------------------------------------
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