[mercury-users] insts and modes question
Raphael Collet
rco at missioncriticalit.com
Thu Apr 15 17:17:29 AEST 2010
Dear Vladimir,
Mercury is not a real logic programming language. Think of it as a functional language syntactically dressed like a logic language. But the fundamentals of logic programming (the logic variables) have been ruled out of the language.
I have tried myself to figure out how to use modes to extend the usability of the language (in the LP sense), but I gave up. Modes and insts are too limited in practice to do that. Partially instantiated data structures are not supported, and AFAIK there is no plan to support it in the near future.
Regards,
Raphael
Vladimir Gubarkov wrote:
> 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 -->
> {
> (
> f(a(7,Q1))
> ->
> Q = Q1
> ;
> Q = -1
> )
> },
> io.write_int(Q),
> io.nl <http://io.nl>.
>
> 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
> future?
>
> 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,
> Vladimir.
--------------------------------------------------------------------------
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