[mercury-users] Exceptions, determinism and purity

Ralph Becket rafe at csse.unimelb.edu.au
Fri Mar 7 14:36:26 AEDT 2008


Nicholas Nethercote, Friday,  7 March 2008:
> 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.

Yes, this is a sticky one and it's related to the handling of trace
goals.

The declarative semantics of p mean that it can be optimised away.
If you don't want that to happen, you should declare p to be impure.
This is reasonable because your program is depending upon the
operational semantics of p.
--------------------------------------------------------------------------
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