[m-users.] When is nondeterminism appropriate?

Philip White philip at pswhite.org
Mon Feb 15 07:32:01 AEDT 2021


Hello,

I'm confused when it is a good idea to make functions and predicates
that are anything but deterministic. Whenever I write a function that
could potentially not have any solutions, often that failure has the 
possibility that it can trickle up to the top of the application and
need to be displayed to the user. Since I want to give the best
possible error message, I want to store a message about the cause of
the error with all the context about why it was caused, instead of
printing a generic "Error". To do this, I often use a result type:

:- type result ---> ok(T) ; error(string).

"functions that can fail" (either because of user error or something
else) seems like the perfect time to use semidet, but if I
want to have good error messages, then semidet will not help me, and I
might as well try to make my function deterministic.

I have two questions:

1. Can someone give a real example of when nondeterminism has been
useful?

2. Is there a way to track "functions that can fail" while also
maintaining info about that failure?

The language reference manual explains technically how determinism
modes work, but it doesn't give much guidance on how to pick the
appropriate determinism.

Thanks,
Philip


More information about the users mailing list