Modified layout for lambda-case
Tyson Whitehead
twhitehead at gmail.com
Mon Jul 9 23:37:58 CEST 2012
It seems my suggestion isn't getting too much traction.
It occurs to me this may be because I jumped right into layout rules and
didn't first give some simple motivating examples to get the idea across.
SHORT VERSION:
Assume '\' is a grouping construct. I proposed always interpreting
... \x -> do (3a)
...
as
... \ { x -> do { ... } } (3b)
and never as
... \ { x -> do { }; ... } (3c)
or
... \ { x -> do { } } ... (3d)
This would be apposed to our current situation of all these being possible
depending on if the second line starts past (3c), at (3b), or before (3d) 'x'.
We loose nothing is at best empty groups do nothing (let and where) and at
worst are errors (do and case) as in the above.
LONGER VERSION:
What I was suggesting was to change the layout rule that gives you empty
groupings. Currently nonsensical nested empty where and let clauses like
let { x = ... where { }; ... } (1a)
do { let { }; ... } (2a)
can be expressed using layouts
let x = ... where (1b)
...
do let (2b)
...
because each new grouping has to be indented further than the previous. This
trips us up if we change '\' into a grouping construct as the common
... \x -> do (3a)
...
will get interpreted incorrectly as
... \ { x -> do { } } ... (3d)
It all seems silly though. At best empty grouping does nothing (let and
where) and at worst is an error (do and case). Why then not always go with
... \ { x -> do { ... } } (3b)
That is, if a line ends in a grouping clauses and the next line is further
indented, then what follows is the associated grouped statements.
It's also easier to read. Further indented lines following a grouping clause
are associated with that clause. No need to identify other potential grouping
clauses and check relative indentation levels.
Cheers! -Tyson
More information about the Glasgow-haskell-users
mailing list