[mercury-users] functions vs predicates (was Re: State variable problem
Peter Schachte
schachte at csse.unimelb.edu.au
Tue Aug 15 11:30:44 AEST 2006
On Mon, Aug 14, 2006 at 06:38:28PM +1000, Mark Brown wrote:
> > Do they have problems
> > other than with negation?
>
> I think the real problem is that `X = X' doesn't hold, but people would
> naturally expect it to.
I'm not so sure what people's natural expectation is in this case. If
our domain is the natural numbers, would you expect 0-1 = 1-2? I
guess I wouldn't be surprised either way. How about 1/0 = 2/0?
The same issue arises with "referential transparency." What does it
mean to say you can replace an expression with its value when an
expression doesn't actually *have* a value? I guess I'd think of that
case as being vacuously referential transparent: when it does have a
value, you can replace it.
Anyway, on further reflection, I don't think my suggestion solves the
problem, either. Suppose f/1 is a partial function, and that f(1) and
f(2) fail. What is the right answer to the goal f(1) = f(2)?
Currently Mercury will say no; that doesn't seem right to me.
Certainly the way it handles f(1) \= f(1) isn't right. If you take my
suggestion, f(1) \= f(1) will fail, but so will f(1) = f(1), and that
doesn't seem right, either. And my suggestion doesn't do anything
about how Mercury handles f(1) = f(2).
I've written out, and deleted, several other ways to model partial
functions, but they all go wrong somewhere. One of them makes f(1) =
f(2) and f(1) = f(1) succeed, and their negations fail, but then it
goes wrong elsewhere. I guess I'm reluctantly coming to the
conclusion that the best way to deal with partial functions is the way
other programming languages handle them: through exceptions.
Alternatively, having the function return a maybe type gives pretty
good behavior and avoids the need for lots of catches.
--
Peter Schachte Reality is for those who can't face Science
schachte at cs.mu.OZ.AU Fiction.
www.cs.mu.oz.au/~schachte/
Phone: +61 3 8344 1338
--------------------------------------------------------------------------
mercury-users mailing list
Post messages to: mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions: mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the users
mailing list