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 declarationsis good.I thought so too at first but, having thought about it for a while, I nowsee this will cause /major/ problems. The precedence relations asdeclared 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 causedsimply 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 asnon-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 classas 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 oflarge operator classes. Thus one single bad declaration can tear a gapinghole 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 << 3&&4 | 17 (yes, the horrific whitespace is deliberate!)
Although one could view this as a bug in the offending module it makes me somewhatuneasy that one additional import can have such a drastic effect on thecode 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