[mercury-users] Tabling brokenness
    Peter Hawkins 
    hawkinsp at cs.stanford.edu
       
    Tue Jul 18 03:19:33 AEST 2006
    
    
  
Hi..
The following program ostensibly computes the Towers of Hanoi:
:- module hanoi.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
:- import_module int.
:- pred hanoi(int::in) is nondet.
hanoi(N) :- dohanoi(N,3,1,2).
:- pragma memo(dohanoi/4).
:- pred dohanoi(int::in, int::in, int::in, int::in) is nondet.
dohanoi(0, _, _, _).
dohanoi(N, A, B, C) :-
    N > 0,
    N1 = N - 1,
    dohanoi(N1, A, C, B),
    dohanoi(N1, C, B, A).
main(!IO) :-
    (if hanoi(100) then
        print("yes\n", !IO)
     else
        print("no\n", !IO)
    ).
Running it gives this:
$ ./hanoi
Uncaught Mercury exception:
Software Error: detected need for minimal model in pred hanoi.dohanoi/4
Stack dump not available in this grade.
Eh? dohanoi/4 can't possibly loop -- it's decreasing in the first 
argument. Am I missing something really trivial here?
Cheers,
Peter
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at csse.unimelb.edu.au
administrative address: owner-mercury-users at csse.unimelb.edu.au
unsubscribe: Address: mercury-users-request at csse.unimelb.edu.au Message: unsubscribe
subscribe:   Address: mercury-users-request at csse.unimelb.edu.au Message: subscribe
--------------------------------------------------------------------------
    
    
More information about the users
mailing list