Re: How to fight semideterminism in Mercury?

From: Bart Demoen (bmd_at_cs.kuleuven.ac.be)
Date: 10/17/04


Date: Sun, 17 Oct 2004 12:32:51 +0200

Dmitri Soshnikov wrote:

> :- type tree(T) ---> nil; tree(T,avltree(T),avltree(T)).
> :- type avltree(T) ---> tree(T)/int.
>
> When we come to element addition predicate, it is defined as follows:
>
> :- func add(int,avltree(int)) = avltree(int).
> :- mode add(in,in) = out is semidet.
> add(X,nil/_) = tree(X,nil/0,nil/0)/1.
> add(X,tree(Y,L,R)/H) = Res :-
> X<Y ->
> tree(Z,L1,R1)/_ = add(X,L),
> Res = combine(L1,Z,R1,Y,R);
> X>Y ->
> tree(Z,L1,R1)/_ = add(X,R),
> Res = combine(L,Y,L1,Z,R1);
> Res = tree(X,L,R)/H.
>

Can you also show your code for combine/5 ?
Isn't that where one should be able to see that
Res is always a non-emtpy tree ?

Cheers

Bart Demoen