[mercury-users] Records

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Nov 5 18:54:36 AEDT 1999


On 03-Nov-1999, Juergen Stuber <juergen at mpi-sb.mpg.de> wrote:
> Robert Ernst Johann JESCHOFNIK <rejj at cat.cs.mu.OZ.AU> writes:
> > 
> > Dang.
> > It is just that `^' irks me.. I instantly associate it with things like
> > bitwise operations, pointers in Pascal, etc. 
> 
> Not to forget the existential quantification in Prolog.

Existential quantification isn't used often enough
in Prolog to make that an important consideration, IMHO.

Mercury already has a fine syntax for existential quantification
(`some [Vars] ...').  I don't think we are likely to ever
support `^' as existential quantification.

> > I just get the feeling that it is rather `ugly' syntax;
> > 
> > 	Field1 = X ^ field1,
> > 
> > doesn't look all that nice, and doesn't look like `field1' is a member of
> > `X', 
> 
> I second that.  How about @?

As someone already said, `^' is nice because it is a relatively small
symbol, so you can write it with no whitespace without impairing
readability.  `@' is too dark.  `F = X^field1^field2' is easier to read
than `F = X at field1@field2', IMHO.

`@' is also used in the `@<', `@>', etc. term comparison operators.
The Mercury standard library module library/prolog.m, which contains
Prolog-like definitions of various operators, defines these.

> Even better would be a dot.  I know that it is planned to make
> `.' the module qualifier eventually, but I think it would be
> a better idea to junk that proposal, keep `:' as a module qualifier,
> use `::' for types, modes etc. and depreciate `__':

That is a reasonable proposal.
But I think the main trouble with that proposal is that
using `::' for both types qualifiers and mode qualifiers
may lead to some abiguities in the future.

We definitely want to allow explicit type qualifiers in clauses.
Currently the plan is for that to use the syntax `Expression : Type'.
(There's already code in the compiler to handle this, but it's not yet
enabled because `:' is currently used as module qualifier.)

We probably also want to allow different clauses for different modes of
a predicate (perhaps with such predicates defaulting to `impure',
requiring an explicit `pragma promise_pure' if the different modes have
the same semantics); currently this is possible using the C interface,
but it would be nice to have a more direct syntax for that.

Now, if we combine both of those extensions, then you could write

	foo(X : t) :- ...

and

	foo(X :: m) :- ...

and they would mean quite different things.
You could even use them both in the same clause:

	foo(X : t :: m) :- ...

If `::' is to be used for both type and mode qualifiers,
then that wouldn't work.

> - Nothing has happened on this front for two years (I think?),
>   it doesn't seem important.

I've always considered it important.  The main reason for it not having
been done yet is just that this is a somewhat difficult issue, since it
requires considering the needs of all of the different parts of the
language, including some parts such as record syntax which were
anticipated but had not yet been designed.  You need to also consider
the relationship with operators used in other languages.  So it
requires quite a bit of expertise.  But it's not really "research"
in the sense that it is unlikely to lead to publications,
which ultimately drive one of our main sources of funding.
And there are lots of other interesting and important things to do.
So it is hard to find the time for this kind of thing.

> - I still have to use `:' as a module qualifier for infix ops,
>   `.' is not implemented.

Generally I wouldn't recommend using any module qualifier
at all for infix ops like `+'.

But in recent development versions, we allow

	Foo `qualifier__infix_op` Bar

and hence

	Foo `'int__+'` Bar

Or of course you can use prefix:

	'int__+'(Foo, Bar)

> - The change would eventually break existing software.

You mean software using `__'?
That's true, but we can probably provide automated tools
to convert existing software.

> - It offers very little benefit.

One benefit is that it allows us to provide a nice
syntax for the two extensions discussed above.

Of course, as with any discussion of syntax, the real
benefits are mostly aesthetic.

> - Haskell uses `::' for type declarations.
> - `:' as a module qualifier is Prolog tradition :-)

True, but these languages are outnumbered:
there are more languages which use `.' as module
qualifier and `:' as type qualifier.

Still, I'm interested in hearing alternative proposals,
so if you can come up with a good solution to the issue
of type and mode qualifiers (see above), then I'd be
very interested to hear about it.

Cheers,
	Fergus.

-- 
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.
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list