Re: [Haskell-cafe] Re: non-total operator precedence order (was:Fractional/negative fixity?)

2006-11-10 Thread Henning Thielemann

On Fri, 10 Nov 2006, Benjamin Franksen wrote:

 Although one could view this as a bug in the offending module it makes
 me somewhat uneasy that one additional import can have such a drastic
 effect on the code in a module /even if you don't use anything from that
 module/.

It's the same as with instance declarations, isn't it? I don't want to
defend the problems arising with todays anonymous instance declarations,
but I think a simple error report is better than trying to solve the
problem automatically and thus hide it from the programmer.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: non-total operator precedence order (was:Fractional/negative fixity?)

2006-11-10 Thread Jan-Willem Maessen


On Nov 9, 2006, at 7:16 PM, Benjamin Franksen wrote:


Carl Witty wrote:


On Thu, 2006-11-09 at 22:20 +0100, Benjamin Franksen wrote:

Henning Thielemann wrote:
 Maybe making fixity declarations like type class instance  
declarations

 is
good.


I thought so too at first but, having thought about it for a  
while, I now

see this will cause /major/ problems. The precedence relations as
declared explicitly by the programmer must form a DAG, with the  
vertices
being the operator classes with equal precedence. There are two  
ways you
can break the DAG: by introducing a 'smaller' or 'larger'  
relation when
another module has already declared them to have equal precedence  
(resp.

the other way around); or by introducing a cycle. Both can be caused
simply by importing yet another module. I think it would be  
unacceptable
not to provide some way for the programmer to resolve such  
conflicts.


[ ... possibilities for resolving conflicts omitted ... ]

Another possibility is:

If you have operators op1 and op2, where the compiler sees  
conflicting
requirements for the precedence of op1 and op2, then they are  
treated as

non-associative relative to each other: the expression
  a op1 b op2 c
is illegal, and the programmer must instead write
  (a op1 b) op2 c
or
  a op1 (b op2 c)


It's a possibility. However, I fear that such conflicting  
precedences might
not come in nice little isolated pairs. For instance, each operator  
that is
in the same precedence class as op1 (i.e. has been declared as  
having equal
precedence) will now be 'incompatible' with any that is in the same  
class

as op2, right?


Well, look at it from the perspective of the reader.  Does the reader  
of your code know beyond a shadow of a doubt what the intended  
precedence will be in these cases?  If not, there should be  
parentheses there---quite apart from what the parser may or may not  
permit you to do.  If the parser can't figure it out, you can bet  
your readers will have trouble as well.



It gets worse if the conflict creates a cycle in a chain of
large operator classes. Thus one single bad declaration can tear a  
gaping

hole into an otherwise perfectly nice and consistent DAG of precedence
order relations, possibly invalidating a whole lot of code.


Requiring parenthesization solves these problems in a stroke.

-Jan-Willem Maessen
 who can't reliably parenthesize the C expression   a==b  34 | 17
 (yes, the horrific whitespace is deliberate!)



Although one
could view this as a bug in the offending module it makes me somewhat
uneasy that one additional import can have such a drastic effect on  
the

code in a module /even if you don't use anything from that module/.

Ben

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe




smime.p7s
Description: S/MIME cryptographic signature
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: non-total operator precedence order (was:Fractional/negative fixity?)

2006-11-09 Thread Benjamin Franksen
Carl Witty wrote:

 On Thu, 2006-11-09 at 22:20 +0100, Benjamin Franksen wrote:
 Henning Thielemann wrote:
   Maybe making fixity declarations like type class instance declarations
   is
  good.
 
 I thought so too at first but, having thought about it for a while, I now
 see this will cause /major/ problems. The precedence relations as
 declared explicitly by the programmer must form a DAG, with the vertices
 being the operator classes with equal precedence. There are two ways you
 can break the DAG: by introducing a 'smaller' or 'larger' relation when
 another module has already declared them to have equal precedence (resp.
 the other way around); or by introducing a cycle. Both can be caused
 simply by importing yet another module. I think it would be unacceptable
 not to provide some way for the programmer to resolve such conflicts.
 
 [ ... possibilities for resolving conflicts omitted ... ]
 
 Another possibility is:
 
 If you have operators op1 and op2, where the compiler sees conflicting
 requirements for the precedence of op1 and op2, then they are treated as
 non-associative relative to each other: the expression
   a op1 b op2 c
 is illegal, and the programmer must instead write
   (a op1 b) op2 c
 or
   a op1 (b op2 c)

It's a possibility. However, I fear that such conflicting precedences might
not come in nice little isolated pairs. For instance, each operator that is
in the same precedence class as op1 (i.e. has been declared as having equal
precedence) will now be 'incompatible' with any that is in the same class
as op2, right? It gets worse if the conflict creates a cycle in a chain of
large operator classes. Thus one single bad declaration can tear a gaping
hole into an otherwise perfectly nice and consistent DAG of precedence
order relations, possibly invalidating a whole lot of code. Although one
could view this as a bug in the offending module it makes me somewhat
uneasy that one additional import can have such a drastic effect on the
code in a module /even if you don't use anything from that module/.

Ben

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe