Fixity resolution, possible specification

Simon Marlow simonmarhaskell at gmail.com
Mon Feb 19 08:17:04 EST 2007


Twan van Laarhoven wrote:

> Add subsection:
> === 3.4.1 Fixity Resolution ===
> 
> Fixity resolution is applied after parsing to convert all operator 
> applications to the form @e1 qop e2 at .
> 
> Fixity resolution is specified by the following algorithm:
>   Let $e$ be an expression anywhere in the parse tree consisting of 
> alternating operators and expressions.
>   Let $O$ be the list of operator with the lowest precedence level among 
> those in $e$.
>   If all operators in $O$ are declared left-associative (@infixl@), then:
>     -> $e$ is split at the rightmost element $o$ of $O$.
>        Splitting means that in the parse tree, $e$ is replaced by 
> @(everything in $e$ before $o$) $o$ (everything in $e$ after o)@.
>   If all operators in $O$ are declared right-associative (@infixr@), then:
>     -> $e$ is split at the leftmost element of $O$.
>   If $O$ contains a single operator which is declared non-associative 
> (@infix@), then:
>     -> $e$ is split at that operator.
>   In all other cases
>     -> an error is reported.
> 
>   This process is repeated until all expressions contain a single operator.
> 
> The fixity resolution is also applied to sections (see Section 3.5).

I haven't examined the above algorithm in detail, but it would be much easier to 
check if it were expressed as concrete Haskell code.  That's what I had in mind 
when I proposed FixityResolution.  Write a function that takes an 
operator-application expressed left-associatively (or right-associatively) and 
re-associate it according to the precedences of the operators.  It's pretty 
straightforward to write - I have some code lying around somewhere, and GHC 
contains some code that does exactly that.  By all means propose some code (and 
some QuickCheck tests!), that will certainly save us some time.

Cheers,
	Simon


More information about the Haskell-prime mailing list