[mercury-users] Exceptions, determinism and purity
Peter Schachte
schachte at csse.unimelb.edu.au
Fri Mar 7 14:22:36 AEDT 2008
Nicholas Nethercote wrote:
> Hi,
>
> Take this predicate:
>
> :- pred p(int::in) is det.
>
> It is det and doesn't produce any output. So at first glance you'd
> think you could safely remove any call to it.
>
> But, it could be defined like this:
>
> pos(X) :- ( if X >= 0 then true else error("negative!") ).
>
> So removing calls could clearly change a program's behaviour.
Similarly if pos/1 were implemented like:
pos(X) :- pos(X).
If you think of a predicate in terms of its finite success and failure sets,
removing a det goal cannot change the finite failure set, so it doesn't make
anything true that was previously false (nor vice-versa, of course). All it
does is make the code more complete by adding to the finite success set.
Perhaps it's a bit unfortunate that you can't simulate C's assert() in
Mercury by using a det goal with some error cases. It wouldn't be correct
anyway, since the compiler can freely reorder the test after where it's needed.
--
Peter Schachte We should not focus on giving any one group an
schachte at cs.mu.OZ.AU especially good life, but on giving the greatest
www.cs.mu.oz.au/~schachte/ possible life for the community as whole.
Phone: +61 3 8344 1338 -- Plato
--------------------------------------------------------------------------
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