[m-dev.] Impurity syntax

Ralph Becket rafe at cs.mu.OZ.AU
Mon Aug 16 11:12:46 AEST 2004

Zoltan Somogyi, Friday, 13 August 2004:
> On 13-Aug-2004, Ralph Becket <rafe at cs.mu.OZ.AU> wrote:
> What you are proposing is a minor variant of something that has been
> proposed before, as extended DCGs. We eventually decided to use
> state variable syntax instead, a fact I wouldn't have expected
> to have to remind you of :-)

I remember that debate well!  I'm don't actually think the `LIGHTER
WEIGHT' approach is the right one (although I did for about four hours
last week) for all the reasons you list.  State variables already
present a syntactically light solution to the problem and provide all
the information necessary for the analyses that PJS has in mind.

I do think that annotating every impure/semipure goal is over the top:
code that unavoidably makes impure calls quickly becomes unreadable.
I'd like to see the impure/semipure annotations moved to the head of
each clause.  That is, instead of writing

:- pred my_solver_eq(my_solver::in(any), my_solver::in(any))
		is semidet.
:- pragma promise_pure(my_solver_eq/2).

my_solver_eq(A0, B0) :-
	impure A = 'representation of my_solver/0'(A0),
	impure B = 'representation of my_solver/0'(B0),
	impure my_solver_repn_eq(A, B).

I'd like to write just

impure my_solver_eq(A0, B0) :-
	A = 'representation of my_solver/0'(A0),
	B = 'representation of my_solver/0'(B0),
	my_solver_repn_eq(A, B).

The annotation on the clause head acts as an immediate reminder to the
reader that the given order is significant for some of the subgoals.

I'd even like to go a step further and write

promise_pure my_solver_eq(A0, B0) :-
	A = 'representation of my_solver/0'(A0),
	B = 'representation of my_solver/0'(B0),
	my_solver_repn_eq(A, B).

and do away with the need for an additional pragma (although 
we'd still need to keep the pragma available for foreign code.)

-- Ralph
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au

More information about the developers mailing list