[m-users.] Program questions and inquiry

Julien Fischer jfischer at opturion.com
Mon May 6 14:42:20 AEST 2013


Hi,

On Sun, 5 May 2013, Mark Green wrote:

> Hi, Nice to see that the mailing lists are still going, will Mercury
> still be OK after the move away from Melbourne?

It has been thus far, hopefully it remains so.

> As a learning exercise I have been trying to implement a solver for
> the "river crossing" problem in several logic languages. Below is my
> attempt in Mercury, however, it has a strange problem - namely, it
> only outputs an empty list. Can anyone tell me what's wrong?
> 
> :- module river.
> :- interface.
> :- import_module io.
> :- import_module list.
> :- import_module solutions.
> 
> :- type object ---> chicken; fox; grain; nothing.
> :- type side ---> left; right.
> :- type riverstate ---> state(list(object), list(object), side).
> 
> :- pred eats(object::in,object::in) is semidet.
> :- pred safe(list(object)::in) is semidet.
> :- pred unsafe(list(object)::in) is semidet.
> :- pred doMove(riverstate::in, object::in, riverstate::out) is nondet.
> :- pred canMove(riverstate::in, object::out) is multi.
> :- pred moveSafe(riverstate::in, object::out) is nondet.
> :- pred solves(riverstate::in, riverstate::in, list(object)::out, list(riverstate)::in) is nondet.
> :- pred main(io::di, io::uo) is det.
> 
> :- implementation.
> 
> eats(fox,chicken).
> eats(chicken,grain).
> 
> safe(List) :- eats(A,B), member(A,List), member(B,List).

This is wrong: what you are saying is that if A and B are on the same
bank of the river and A eats B then it is safe -- which it isn't!

Cheers,
Julien.



More information about the users mailing list