[Haskell-cafe] Parse text difficulty

Simon Marlow simonmar at microsoft.com
Fri Dec 10 13:38:14 EST 2004


On 09 December 2004 16:37, Malcolm Wallace wrote:

> Robert Dockins <robdockins at fastmail.fm> writes:
> 
>>>   Prelude> [1..5] `zipWith (+)` [7..]
>>>   <interactive>:1: parse error on input `('
>> 
>> is there a technical reason for this or did it just happen?
> 
> If you are asking why general expressions are prohibited between
> backticks, yes, there is a reason.  The expression could be
> arbitrarily large, so you might have to search many lines to find the
> closing backtick.  But in such a situation, it is surely much more
> likely 
> that the programmer has simply forgotten to close the ticks around
> a simple identifier.  Just think of the potential for delightfully
> baffling type error messages that might result!

Forgetting to close a tick would lead to an odd number of ticks, which
would probably be flagged as a parse error.  Unless you had an even
number of missing ticks, of course :-)

You can't allow completely general expressions inside backticks,
otherwise you run into ambiguity with:

  1 `plus` 2 + 3 `plus` 4

so, is that 

  (plus 1 2) + (plus 3 4)

or is it
   
  ((2+3) plus plus) 1 4

So it would have to be `fexp` only (see the Haskell grammar for fexp).

And there's fixities: you can specify the fixity of `x`, but it doesn't
make sense to specify the fixity of an expression.

There's a historical reason too: `x` and (+) used to be single lexical
tokens.  I think that changed in Haskell 1.3, but I could be mistaken.

Cheers,
	Simon


More information about the Haskell-Cafe mailing list