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

Benjamin Franksen benjamin.franksen at bessy.de
Thu Nov 9 19:16:23 EST 2006

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


More information about the Haskell-Cafe mailing list