[m-dev.] proposed syntax for typed insts

Zoltan Somogyi zoltan.somogyi at runbox.com
Mon Sep 7 18:51:50 AEST 2015


I am proposing a syntax for typed insts, which we have
long agreed are a good idea.

Currently, inst declarations look like either this:

:- inst Instname(InstArgs) == ...

or like this:

:- inst InstName(InstArgs) ---> ...

I propose that "for TypeName/TypeArity" be added
between the InstName(InstArgs) and the "==" or "---->",
so that they look like this:

:- inst InstName(InstArgs) for TypeName/TypeArity == ...

This can be achieved by adding "for" as a new xfx operator
with a priority that is lower than the priority of either --->,
which is 1179, and of "==", which is 700. (In a perversity
inherited from Prolog, lower priorities bind more *tightly*.)
That way, the part of the term that we read in for an inst
definition with have InstName(InstArgs) for TypeName/TypeArity
in the slot that used to have just InstName(InstArgs)
(the slot being the left argument term of ---> or ==),  and
everything else will remain the same as far as parsing
the inst definition is concerned. ("inst" is prefix op with
priority 1199, so it binds loosest of all these operators.)

I am attaching a program that reads in terms and prints them
showing the priorities of the relevant ops, two inst definitions
from tree234.m (one with ---> and one with ==), both in their
current untyped form and in the proposed typed form, and the
output of the program on these inst definitions as terms after
"for" is added as an xfx op with priority 500.

What do people think about the proposal? Should the keyword
be something other than "for"? Should we require typed insts
to use :- typed_inst instead of just :- inst? Should the syntax
structure be completely different?

As an aside, is show_ops.m worth adding to extras?

Zoltan.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: show_ops.m
Type: text/x-objcsrc
Size: 3629 bytes
Desc: not available
URL: <http://lists.mercurylang.org/archives/developers/attachments/20150907/6466cc20/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: source_syntax
Type: application/octet-stream
Size: 366 bytes
Desc: not available
URL: <http://lists.mercurylang.org/archives/developers/attachments/20150907/6466cc20/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: source_syntax.ops
Type: application/octet-stream
Size: 1102 bytes
Desc: not available
URL: <http://lists.mercurylang.org/archives/developers/attachments/20150907/6466cc20/attachment-0001.obj>


More information about the developers mailing list