[Haskell-cafe] question automatic indentation (and so on)
cobbe at ccs.neu.edu
Mon Jul 1 13:59:25 CEST 2013
On Mon, Jul 01, 2013 at 09:48:42AM +0200, Joachim Breitner wrote:
> I found https://github.com/jaspervdj/stylish-haskell/ (found via
> http://stackoverflow.com/q/6870148/946226) which formats just some very
> few aspects of Haskell. Does anyone have a more complete solution? Or is
> interested in creating one?
I'd love a fully-automatic indentation tool; it's one of the things about
the Lisp world that I miss. But is this actually a solvable problem? I
think that, to be fully correct, an indentation algorithm for Haskell would
have to know not only the syntactic structure of the program but also the
programmer's intent, in some cases.
Heh -- forgive the pun. Nested CASE expressions are actually one of the
trickiest bits. If the programmer doesn't put parens around the inner
expression (and doesn't use braces and semis), then only indentation serves
to indicate when the inner case ends and the next branch of the outer case
case x of
A -> ...
case y of
Just z -> ...
Nothing -> ...
C -> ...
Similarly (tying this back to my original question), in a do block,
applications that span multiple lines are tricky:
do f x y z
a b c
How does the indentation tool know if (a b c) is supposed to be the next
item in the do block, or merely a continuation of the previous application
More information about the Haskell-Cafe