On Wed, 2008-01-23 at 16:08 -0500, Kevin Reid wrote:
> On Jan 23, 2008, at 15:10, Jonathan S. Shapiro wrote:
> 
> > On Wed, 2008-01-23 at 19:52 +0000, Sam Mason wrote:
> >> Haskell has a nice feature where any sequence of punctuation  
> >> characters
> >> is treated as an infix operator.
> > ...
> > I'm also not sure that this feature obeys lexical scoping  
> > constraints. Does it? If not, then my negative opinion about it  
> > goes up exponentially.
> 
> It most certainly does. Ordinary identifiers and 'operator  
> symbols' (to use the language of the Haskell 98 Report) are identical  
> except in parsing; the semantics do not vary, and each can be used in  
> place of the other with appropriate markers.

So if I introduce a left-associative operator with priority N, when does
that *priority* go out of scope? Particularly if type classes over that
operator are in effect (because type class instances don't obey scoping
rules in general).

It's actually not the non-identifier operators per say that are the
source of concern here. It's the fact that the human auditor has
difficulty keeping the operator precedence rules in their head if they
can change.

For example, suppose you and I both use !#! as a new operator in two
unrelated operators, but we use it with different associativity and/or
priority in our mixfix specifications. Now consider the impact on the
human auditor as they trace a call from one module to another. Every
time they cross a module boundary, they have to be prepared to replace
their mental operator precedence table.

Mixfix is one of those features that provides a benefit when it is used
well, but also provides a really good way of shooting your foot off when
it is used badly.

>  From http://www.haskell.org/onlinereport/exps.html :
> > An operator is either an operator symbol, such as + or $$, or is an  
> > ordinary identifier enclosed in grave accents (backquotes), such as  
> > `op`. For example, instead of writing the prefix application op x  
> > y, one can write the infix application x `op` y. If no fixity  
> > declaration is given for `op` then it defaults to highest  
> > precedence and left associativity (see Section 4.4.2).
> >
> > Dually, an operator symbol can be converted to an ordinary  
> > identifier by enclosing it in parentheses. For example, (+) x y is  
> > equivalent to x + y, and foldr (*) 1 xs is equivalent to foldr (\x  
> > y -> x*y) 1 xs.

In the absence of priority specification when the operator is
introduced, I concur that those rules are pretty easy to follow. It's
the ability to change precedence that is the source of potential
auditing confusion.


shap

_______________________________________________
bitc-dev mailing list
[email protected]
http://www.coyotos.org/mailman/listinfo/bitc-dev

Reply via email to