[mercury-users] constructor class syntax

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Nov 3 02:30:37 AEDT 1999


On 02-Nov-1999, Michael Day <mikeday at corplink.com.au> wrote:
> 
> [Ralph wrote:] 
> > Hasn't Mercury got a lot of equivalence operators (=, ==, ::)?  Is there
> > any need for so many?

The syntax of the Mercury type system was strongly influenced by the
syntax of the NU-Prolog type system.  In the NU-Prolog type system,
`:- type t1 = t2.' and `:- type t1 == t2.' meant different things. 
`==' meant that the two types were truly interchangable, but with `=',
the semantics were more complicated; `:- type t1 = t2 + t3.' was used
for undiscriminated union types, and there was some special meaning
attached to `type t1 = t2.' (it was never very clear to me exactly what
that meaning was).  Mercury used `==' because Mercury's type
equivalence was like NU-Prolog's `==' rather than like NU-Prolog's `='.

At this point NU-Prolog compatibility is not very important now, so I
guess you could put that one down to "hysterical raisons".  We could
change the language definition to allow `=' instead of `==' in `type'
definitions, I suppose.

The reason for using `::' for mode equivalence definitions
is that `=' and `==' don't work well because they have the
wrong operator precedence.  See below.

> Is the use of :: in mode definitions vaguely isomorphic to its (future)
> use in denoting field names in structures?

I think we will probably end up using `:' for field names.
Simon Taylor's current implementation is using `::', but
I think the main reason for that is that `:', which was
Zoltan's original choice, didn't work because it clashed
with the use of `:' as module qualifier.
But I think in the long run we will use `.' as module
qualifier and `:' as type qualifier, including the `<field_name> : <type>'
syntax in records.

> :- mode out = free -> ground.

That doesn't work well, because it parses the same as

	:- mode (out = free) -> ground.

So either the compiler needs to recognize and allow that (ugh),
or the user needs to use explicit parentheses every time (not
very nice either).  That's why we chose to use a different
operator.  We chose `::' because `:: <mode>' was already
used in combined pred/mode declarations, e.g.

	:- pred foo(int::in, int::out) is det.

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