[m-dev.] for review: tuples [1]

Fergus Henderson fjh at cs.mu.OZ.AU
Sat Aug 12 01:57:34 AEST 2000


On 11-Aug-2000, Peter Schachte <schachte at cs.mu.OZ.AU> wrote:
> On Sun, Aug 06, 2000 at 02:36:59PM +1000, Simon Taylor wrote:
> > >     2)  Much more orthodox notation mathematically (Using parentheses for
> > > 	tuples is only a little less common than angle brackets; they're
> > > 	certainly a *lot* more orthodox than braces).
> > Not using parentheses was a deliberate decision so that unary tuples work
> > when passed to a predicate which takes a polymorphic argument which is
> > expected to be a tuple of any arity. If unary tuples don't work, then the
> > arity needs to be passed separately so that the unary case can be handled
> 
> Ok, but braces just don't *look* right for tuples.

I think that is a matter of familiarity as much as anything.
But Mercury would not be the first language to use braces for tuples:
that's what Erlang uses.

> > >     3)  Doesn't take away the orthodox notation for sets.  It would be nice to
> > >         reserve braces for sets at some later time.
> > 
> > I can't see this being useful. list_to_set([1, 2, 3]) is not that
> > much worse than {1, 2, 3}.
> 
> Matter of taste, I guess.  I think list_to_set([1, 2, 3]) is much less
> readable than {1,2,3}.  Writing {[1,2,3]} wouldn't be too bad, and could be
> easily accomplished by defining func {}/1 as an alias for list_to_set.  Or
> does your change prevent me from defining {}/1 as a function?  If it does,
> this is not a backward compatible change.

The change allows (or at least I think it should allow) other uses for
the symbols, so long as you specify the types enough to ensure that
type inference can resolve any ambiguities.

> How hard would it be to use the obvious syntax for tuples:  < ... > ? Less
> than is not currently a prefix operator, so it wouldn't be a problem.  The
> only problem is that greater than is an infix op, so it would be difficult to
> tell an infix greater than from the tuple terminator (maybe impossible in some
> cases, but I can't think of any).  But I don't think it would be too
> unreasonable to specify that if you want to use an infix greater than inside a
> tuple, then you have to parenthesize the term.  It's not going to happen very
> often, and I think it would be worth it to use angle brackets for tuples
> rather than braces.

I spent about an hour looking at this and got about half way, but
there are certainly some tricky cases... for example, currently the
following is valid syntax:

	f(<,>,<,>).

This is a term f/4 whose arguments are all '<'/0 or '>'/0.
Note that we do actually make use of syntax like this, e.g. in
library/list.m we have `compare(<, X, Y)'.

Also if you write `<(...' then the parser has to decide:
is this a term with `<' as the top-level functor, or is it
the beginning of a tuple whose first argument is parenthesized?
Existing code such as library/float.m assumes the former interpretation,
but that may be counter-intuitive for tuple users.

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