[mercury-users] impure predicates
Fergus Henderson
fjh at cs.mu.OZ.AU
Wed Oct 21 05:18:32 AEST 1998
On 20-Oct-1998, Ralph Becket <rwab1 at cam.sri.com> wrote:
> Fergus Henderson wrote on 21 Oct:
> >
> > > I'd say no. Typically, a predicate with no output args is going to be
> > > semidet or erroneous (anything else doesn't make much sense to me).
> >
> > Typically, you're right, but `impure' procedures are not supposed
> > to be typical! ;-)
>
> Aaagh! I feel the unholy influence of Larry Wall creeping in here!
Well, if Mercury is ever as popular as Perl, I'll be pretty happy ;-)
If you have a look at the details of how we handle impure code,
you will see that impure code can't creep up and surprise anyone.
Any predicate which is impure must be labelled as such in its
declaration, and every call to an impure predicate must be
preceded by the word `impure'. Furthermore, all of this is
statically checked by the compiler. So if you use impure code,
it will be glaringly obvious to anyone reading your code.
The point of allowing impure code is not to encourage people
to use impure code when otherwise they might have used pure code;
it is to encourage them to use impure Mercury when otherwise
they would have been forced to program at an even lower level,
for example by using the C interface.
The vast majority of the time, you can do what you want just using pure code.
But occaisionally there may be times when you want or need to use impure
code. Mercury's support for impure code lets you do that in a disciplined
way, without lying to the compiler or using a foreign language interface
to go behind its back, and the static checking of impurity declarations
helps you to ensure that the impurity is confined to well isolated and
clearly marked sections of your code.
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- the last words of T. S. Garp.
More information about the users
mailing list