[mercury-users] range of input

Robert Ernst Johann JESCHOFNIK rejj at cat.cs.mu.OZ.AU
Mon Nov 8 20:13:36 AEDT 1999


Hello.

As I was walking home from the train station this evening, I found myself
thinking that it would be nice if there were a way to tell the compiler
the range of input a particular predicate will receive for each variable.
This would allow you to use pattern matching / switches with a
non-exhaustive set of constructors.

That wasn't all too clear, so here is an attempt to show what I mean:

:- pred  fib(int, int).
:- mode  fib(in, out) is det.
:- range fib({1;2;>=3}, all).

fib(1, 1).
fib(2, 1).
fib(X, Y) :-
	fib(X1, Y1),
	fib(X2, Y2),
	X + 1 = X1,
	X + 2 = X2,
	Y1 + Y2 = Y.


Given "range" information, this wouldn't have to be semidet or multi. Any
call out of the promised range should call error/1.

And yes, I'm sure the syntax for the range could/should be much nicer, but
I'm just interested in the idea at the moment. Does this seem viable?


Rob
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list