Call to arms: lambda-case is stuck and needs your help

Simon Marlow marlowsd at gmail.com
Mon Jul 9 14:44:08 CEST 2012


On 07/07/2012 05:08, Tyson Whitehead wrote:

> PS:  To be fully precise, the modified layout decoder in 9.3 would be
>
>    L (<n>:ts)     i (m:ms) = ; : (L ts n (m:ms))   if m = n
>                            = } : (L (<n>:ts) n ms) if n < m
>    L (<n>:ts)     i ms     = L ts n ms
>    L ({n}:<n>:ts) i ms     = { : (L ts n (n:ms))   if n > i (new rule)
>    L ({n}:ts)     i (m:ms) = { : (L ts i (n:m:ms)) if n > m  (Note 1)
>    L ({n}:ts)     i []     = { : (L ts i [n])      if n > 0  (Note 1)
>    L ({n}:ts)     i ms     = { : } : (L (<n>:ts) i ms)       (Note 2)
>    L (}:ts)       i (0:ms) = } : (L ts i ms)                 (Note 3)
>    L (}:ts)       i ms     = parse-error                     (Note 3)
>    L ({:ts)       i ms     = { : (L ts i (0:ms))             (Note 4)
>    L (t:ts)       i (m:ms) = } : (L (t:ts) i ms)   if m /= 0 and parse-error(t)
> (Note 5)
>    L (t:ts)       i ms     = t : (L ts i ms)
>    L []           i []     = []
>    L []           i (m:ms) = } : L [] i ms         if m /= 0 (Note 6)
>
>    http://www.haskell.org/onlinereport/syntax-iso.html
>
> As before, the function 'L' maps a layout-sensitive augmented token stream to
> a non-layout-sensitive token stream, where the augmented token stream includes
> '<n>' and '{n}' to, respectively, give the indentation level of the first token
> on a new line and that following a grouping token not followed by '{'.
>
> This time though, we allow the '{n}' '<n>' sequence (before it was supressed
> to just '{n}').  We also add a new state variable 'i' to track the indentation
> of the  current line.  The new rule now opens a grouping over a newline so
> long as the indentation is greater than the current line.
>
> Upon a less indented line, it will then close all currently open groups with
> an indentation less than the new line.

It's a little hard to evaluate this without trying it for real to see 
whether it breaks any existing code.  However, unless there are very 
strong reasons to do so, I would argue against making the layout rule 
*more* complicated.  I find the current rule behaves quite intuitively, 
even though its description is hard to understand and it is virtually 
impossible to implement.

I now think '\' is too quiet to introduce a new layout context.  The 
pressing need is really for a combination of '\' and 'case', that is 
single-argument so that we don't have to write parentheses.  I think 
'\case' does the job perfectly.  If you want a multi-clause 
multi-argument function, then give it a name.

Cheers,
	Simon



More information about the Glasgow-haskell-users mailing list