Tyson Richard DOWD
trd at students.cs.mu.oz.au
Thu Sep 25 12:13:34 AEST 1997
Tomas By wrote:
> Suppose I have the following types:
> :- type a(X,Y) ---> x(X) ; y(Y) ; z(int).
> :- type i ---> [...].
> :- type j ---> [...].
> :- type m ---> [...].
> :- type n ---> [...].
> and I want a single procedure 'p/1' that handles things of the types:
You have 4 different types here. If you want a single predicate to
handle these cases, you'll need to put wrappers around them.
Create a new type
:- type b ---> w(a(i,m)) ; x(a(i,n)) ; y(a(j,m)) ; z(a(j,n)).
So p operates on b
Or: Create two new types:
:- type c ---> q(i) ; r(j).
:- type d ---> s(n) ; t(m).
So p operates on a(c,d).
Which one you choose really depends on the problem domain - if
the operations involving i and j are separate to m an n (as it
appears to be because of the definition of a), then the second
alternative may be more natural.
I think there are other alternatives that involve unimplemented
Tyson Dowd # Another great idea from the
# people who brought you
trd at .cs.mu.oz.au # Beer Milkshakes!
http://www.cs.mu.oz.au/~trd # Confidence --- Red Dwarf
More information about the users