|
|
**Ticket:**[\#30](https://gitlab.haskell.org//haskell/prime/issues/30)
|
|
|
# Proposal: \<name\>
|
|
|
|
|
|
<table><tr><th> Type </th>
|
|
|
<th> change
|
|
|
</th></tr>
|
|
|
<tr><th> Status </th>
|
|
|
<th> discussion
|
|
|
</th></tr>
|
|
|
<tr><th> Owner </th>
|
|
|
<th> Simon Marlow
|
|
|
</th></tr>
|
|
|
<tr><th> Section </th>
|
|
|
<th> Syntax Reference
|
|
|
</th></tr>
|
|
|
<tr><th> Dependencies </th>
|
|
|
<th></th></tr>
|
|
|
<tr><th> Related </th>
|
|
|
<th>[NegativeSyntax](negative-syntax)</th></tr></table>
|
|
|
|
|
|
## Compiler support
|
|
|
|
|
|
<table><tr><th> GHC </th>
|
|
|
<th> full (no flag)
|
|
|
</th></tr>
|
|
|
<tr><th> nhc98 </th>
|
|
|
<th> full (no flag)
|
|
|
</th></tr>
|
|
|
<tr><th> Hugs </th>
|
|
|
<th> full (no flag)
|
|
|
</th></tr>
|
|
|
<tr><th> UHC </th>
|
|
|
<th> full (no flag)
|
|
|
</th></tr>
|
|
|
<tr><th> JHC </th>
|
|
|
<th> full (no flag)
|
|
|
</th></tr>
|
|
|
<tr><th> LHC </th>
|
|
|
<th> full (no flag)
|
|
|
</th></tr></table>
|
|
|
|
|
|
## Summary
|
|
|
|
|
|
## Description
|
|
|
|
|
|
|
|
|
This is a proposal that doesn't affect anything except the presentation of the report, because all Haskell implementations currently do it this way anyway. There are some legal Haskell programs, according to the report, that aren't accepted by current implementations (see below). I propose we make the language specification match the implementations.
|
|
|
|
|
|
## The Problem
|
|
|
### The Problem
|
|
|
|
|
|
|
|
|
The Haskell 98 context-free syntax includes fixity resolution as part of the grammar, with a fixed number of fixities (\[1..9\]), essentially using macro expansion to define the grammar. Apart from being really ugly, and not corresponding to any known implementation (long ago GHC used a yacc parser formulated like this, but not any more), this gives rise to some constructions that are very hard to parse correctly. For example, the expression:
|
... | ... | @@ -31,7 +73,7 @@ This is legal syntax, and parses as `do { a == b } == c`, again because `==` is |
|
|
|
|
|
As far as I know, no Haskell compiler gets this right.
|
|
|
|
|
|
## The Solution
|
|
|
### The Solution
|
|
|
|
|
|
|
|
|
These constructions rely on the parser being aware of operator fixities during parsing, which is an unreasonable restriction - it's often easier to follow imports after parsing a file, rather than during it.
|
... | ... | @@ -44,3 +86,10 @@ This would also let us expand the current paultry set of 9 fixity levels to an a |
|
|
|
|
|
|
|
|
Sample code for resolving fixities is here: [resolve.hs](/attachment/wiki/FixityResolution/resolve.hs)[](/raw-attachment/wiki/FixityResolution/resolve.hs). I believe this implements Haskell 98 fixity resolution, without prefix negation (prefix negation could be added, but we might not need to; see [NegativeSyntax](negative-syntax)). The core of the parser is 12 lines of code, with a few lines of datatype declarations and pretty-printing. Note that there is no upper limit on precedence levels, but there is a lower limit of zero. This code could serve as the basis for specifying fixity resolution in the Haskell' report.
|
|
|
|
|
|
## References
|
|
|
|
|
|
- **Ticket:**[\#30](https://gitlab.haskell.org//haskell/prime/issues/30)
|
|
|
- [resolve.hs](/attachment/wiki/FixityResolution/resolve.hs)[](/raw-attachment/wiki/FixityResolution/resolve.hs)
|
|
|
|
|
|
## Report Delta |
|
|
\ No newline at end of file |