[m-dev.] EDCGs

Peter Nicholas MALKIN pnmalk at cat.cs.mu.OZ.AU
Tue Dec 21 15:01:54 AEDT 1999


Hi,

On Fri, 17 Dec 1999, Fergus Henderson wrote:

> Can you call a DCG from an EDCG or vice versa?

You can call an EDCG predicate from within a DCG by writing the predicate call
in expanded form (i.e. with the hidden arguments listed as normal arguments.
This will produce a warning). Also you can call the predicate using the EDCG
predicate call notation: 

Predicate(...) +hidden(...)

This would have to be surrounded by curly braces.

When you say call a DCG from an EDCG I assume you mean using DCG notation for a
predicate that has hidden variables declared for it. That is fine except that
all predicates that receive hidden variables within the body of the clause (and
also the clause head) need to be written in expanded form (again, this will
produce warnings).

> > There is no overloading allowed for predicates with hidden variables.
> 
> Hmm, that's a bit of a drawback.
> And no type inference either.

It may be reasonably straightforward to implement EDCGs with type inference, and
type overloading. To do so would obviously require to shift the transformation
until after type checking. It would also require a simple tranformation of the
source code to make it compatable with the type checker. Since the only
interface between hidden variables is via the two operators `>:' and `<+',
this can be done by creating dummy predicates for each hidden variable and for
each of the two operators and transforming each occurence of one of the
operators to be a call to the appropriate dummy predicate. A dummy predicate
would have an arity of one and an argument type the same as the hidden variable.
This should be compatable with the type checker.

For instance:

:- htype(app, list(int)).
:- hmode(app, changed(in, out)).

:- pred append(int) +hidden(changed(app)).
:- mode append(in).

append([]).
append(A.As) -->>
	append(As),
	app >: Ls,
	app <+ A.Ls.

This becomes upon transformation before the type checker:

:- htype(app, list(int)).
:- hmode(app, changed(in, out)).

:- pred append(int) +hidden(changed(app)).
:- mode append(in).

:- pred `app_>:'(list(int)).
:- pred `app_<+'(list(int)).

append([]).
append(A.As) -->>
	append(As),
	`app_>:'(Ls),
	`app_<+'(A.Ls).

This will allow the type checker to proceed as normal. It is not a concern that
the hidden variables will not be directly type checked because they always have
the one type and since the EDCG transformation will be preformed by the compiler
there should be no type incorrectness introduced by the EDCG transformation.

A problem with this is slighly obscure error messages that would arise as a
result of the pre-typechecker transformation.

Peter

P.S. I have the current proposed syntax (previous email) working :)

--------------------------------------------------------------------------
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