[mercury-users] Learning Mercury

Eric gluon001 at gmail.com
Sat Aug 11 22:27:17 AEST 2007


I just started using Mercury myself, but have you seen

Prolog to Mercury Transition Guide on this this page
http://www.cs.mu.oz.au/research/mercury/information/documentation.html

Eric


On 8/10/07, Tom Davies <tgdavies at gmail.com> wrote:
> Hi,
>
> I'm learning Mercury by going through Bratko's Prolog programming for
> AI, and I have questions about his Monkey example.
>
> The Prolog version is:
> move(
>        state(middle, onbox, middle, no),
>        grasp,
>        state(middle, onbox, middle, yes)
>        ).
>
> move(
>        state(P, onfloor, P, H),
>        climb,
>        state(P, onbox, P, H)
>        ).
>
> move(
>        state(P1, onfloor, P1, H),
>        push(P1,P2),
>        state(P2, onfloor, P2, H)
>        ).
>
> move(
>        state(P1, onfloor, B, H),
>        walk(P1, P2),
>        state(P2, onfloor, B, H)
>        ).
>
> canget(state(_,_,_,yes)).
>
> canget(S1) :-
>        move(S1,Move,S2),
>        canget(S2).
>
> canget(state(door, onfloor, window, no)).
>
> I have tried to convert this to Mercury (my Mercury code is at the
> end of this email), but get the error:
> Blonder:~/dev/other/bratko tomd$ mmc -v
> Mercury Compiler, version rotd-2007-07-27, configured for i686-apple-
> darwin8.10.1
> ...
> Blonder:~/dev/other/bratko tomd$ mmc --infer-all -E --make monkey
> Making Mercury/cs/monkey.c
> monkey.m:052: In clause for predicate `monkey.canget'/1:
> monkey.m:052:   warning: variable `Move' occurs only once in this scope.
> monkey.m:037: In clause for `move(in, out, out)':
> monkey.m:037:   mode error in conjunction. The next 3 error messages
> indicate
> monkey.m:037:   possible causes of this error.
> monkey.m:034:   In clause for `move(in, out, out)':
> monkey.m:034:   in argument 2 of clause head:
> monkey.m:034:   mode error in unification of `HeadVar__2' and
> `monkey.push(P1,
> monkey.m:034:   P2)'.
> monkey.m:034:   Variable `HeadVar__2' has instantiatedness `free',
> monkey.m:034:   term `monkey.push(P1, P2)' has instantiatedness
> `monkey.push(
> monkey.m:034:     ground,
> monkey.m:034:     free
> monkey.m:034:   )'.
> monkey.m:034:   In clause for `move(in, out, out)':
> ... error log truncated, see `monkey.err' for the complete log.
> ** Error making `Mercury/cs/monkey.c'.
>
> Am I giving the wrong modes for move?
>
> Thanks for any advice.
>
> Tom
>
> :- module monkey.
> :- interface.
> :- import_module io.
> :- pred main(io::di, io::uo) is det.
> :- implementation.
> :- import_module bool.
> :- type horizontal_t ---> door; middle; window.
> :- type vertical_t ---> onbox; onfloor.
> :- type state_t --->
> state(
>        monkeyHorizontal::horizontal_t,
>        monkeyVertical::vertical_t,
>        boxHorizontal::horizontal_t,
>        hasBanana::bool
>        ).
> :- type action_t ---> grasp; climb; push
> (bfrom::horizontal_t,bto::horizontal_t);
>                                        walk(mfrom::horizontal_t,mto::horizontal_t).
>
> :- pred move(state_t,action_t,state_t).
> :- mode move(in,out,out) is nondet.
>
> move(
>        state(middle, onbox, middle, no),
>        grasp,
>        state(middle, onbox, middle, yes)
>        ).
>
> move(
>        state(P, onfloor, P, H),
>        climb,
>        state(P, onbox, P, H)
>        ).
>
> move(
>        state(P1, onfloor, P1, H),
>        push(P1,P2),
>        state(P2, onfloor, P2, H)
>        ).
>
> move(
>        state(P1, onfloor, B, H),
>        walk(P1, P2),
>        state(P2, onfloor, B, H)
>        ).
>
> :- pred canget(state_t).
> :- mode canget(in) is nondet.
>
> canget(state(_,_,_,yes)).
>
> canget(S1) :-
>        move(S1,Move,S2),
>        canget(S2).
>
> main(!IO) :-
>        print(canget(state(door, onfloor, window, no)), !IO).
>
>
>
>
> --------------------------------------------------------------------------
> 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
> --------------------------------------------------------------------------
>
--------------------------------------------------------------------------
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