[mercury-users] insts and modes question

Vladimir Gubarkov xonixx at gmail.com
Thu Apr 15 07:07:50 AEST 2010

Hi, dear sirs

I'm trying to gain with mercury the next prolog idiom:

% code
f(A) :-
    A = a(B,B).

% query
 ?- A = a(7,X), f(A).
A = a(7, 7),
X = 7.

I tried to write something like:

:- module ref.

:- interface.

:- import_module io.
%:- import_module list.

:- pred main(io, io).
:- mode main(di, uo) is det.

:- implementation.

:- type a_type ---> a(int, int).

:- inst a_inst ---> a(ground, free).
:- mode a_mode == a_inst >> ground.

:- pred f(a_type).
:- mode f(a_mode) is semidet.

f(A) :-
    A = a(B,B).

main -->
      Q = Q1
      Q = -1

But mercury (btw, I'm using rotd-2010-04-01-unstable) persistently complains
on this like follows:

$ mmc -e ref.m
ref.m:023: In clause for `f((ref.a_mode))':
ref.m:023:   mode error in unification of `A' and `ref.a(B, V_4)'.
ref.m:023:   Variable `A' has instantiatedness `bound(ref.a(ground, free))',
ref.m:023:   term `ref.a(B, V_4)' has instantiatedness `ref.a(
ref.m:023:     free,
ref.m:023:     free
ref.m:023:   )'.
ref.m:028: In clause for `main(di, uo)':
ref.m:028:   in argument 1 of call to predicate `ref.f'/1:
ref.m:028:   mode error: variable `V_8' has instantiatedness `free',
ref.m:028:   expected instantiatedness was `bound(ref.a(ground, free))'.
For more information, recompile with `-E'.

Yes, I know from documentation, that "The current implementation does not
handle partially instantiated data structures yet.". Is this the case?
I just wonder then what's the use from those (modes, insts)-magic if all
compound insts except for ground and free are hardly useful... Your
clarification is greatly appreciated.
Is there any probability that this feature will be implemented in near

Btw, interesting... If I understand correctly strong typed Tubo Prolog
supported this feature by means of reference domains, but in last version of
Visual Prolog they have dropped this capability.

Sincerely yours,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20100415/a1488447/attachment.html>

More information about the users mailing list