<div dir="ltr"><div><div><div><div><div><div>My current approach is not to have one rule for every case but rather to indent however seems best for the particular code. For example, for Parsec&#39;s &lt;|&gt;, I try to make the code look like a BNF grammar rather than adhering to normal indentation conventions. Perhaps as a carry-over from my C-style programming days, I usually have the operators at the end of the line, but I put &lt;|&gt; at the beginning, several steps *left* of where it would normally be, to get everything aligned nicely. <br>
<br></div>Similarly, I try to align things to show the structure of the code. For example, if I have two similar function calls on top of each other, I try to highlight the parallelism:<br><br></div>    foo (Just $ a + b) Nothing<br>
</div>    foo Nothing          (Just $ a + b)<br><br></div>The main idea is that I try to format my code not based on what the *code* is but based on what it *means*. I don&#39;t know if this is entirely reasonable, but I like it.<br>
<br></div>I&#39;ve thought about writing an automatic indenting tool for Haskell (or, more accurately, a pretty-printer) for another project I have, and this is the main thing that threw me off. While automatic indentation might make sense for less expressive languages (Google Go being an extreme example), I think it would be too constraining for Haskell. After all, in reasonable code, chances are that similar constructs end up meaning wildly different things (especially with the advent of pervasive embedded DSLs), so the code itself is a poor indicator of its own structure. <br>
<br></div>So this is really something of an aside, but I do not think that a gofmt-style tool would be quite as useful for Haskell, and it certainly does not replace good taste.<br><div><div><div><div><div><div><div><div>
<i></i></div></div></div></div></div></div></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jul 1, 2013 at 9:34 AM, Sturdy, Ian <span dir="ltr">&lt;<a href="mailto:sturdyi12@mail.wlu.edu" target="_blank">sturdyi12@mail.wlu.edu</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I always preferred (I think going back to my lisp days)<br>
<br>
    foo x y<br>
          z<br>
<br>
indenting subsequent arguments to the same level as the first, but I have not convinced haskell-mode to do that for me. (The general rule here being that similar things should be at the same indent, which will always result in subexpressions being further indented, but is somewhat more specific.)<br>

<br>
The case I never quite know what to do with is a series of expressions connected with operators, e.g.<br>
<br>
    foo<br>
    &lt;|&gt; bar<br>
    &lt;|&gt; baz<br>
<br>
Leaving operators at the beginning of lines (rather than trailing the previous line) seems preferable, but does one (where the layout rules apply) align the operator or the function? (the alternative being, if your mail client does not make a mess of it with a variable-width font)<br>

<br>
        foo<br>
    &lt;|&gt; bar<br>
    &lt;|&gt; baz<br>
<br>
~IRS<br>
________________________________________<br>
From: <a href="mailto:haskell-cafe-bounces@haskell.org">haskell-cafe-bounces@haskell.org</a> [<a href="mailto:haskell-cafe-bounces@haskell.org">haskell-cafe-bounces@haskell.org</a>] on behalf of Richard Cobbe [<a href="mailto:cobbe@ccs.neu.edu">cobbe@ccs.neu.edu</a>]<br>

Sent: Monday, July 01, 2013 8:00 AM<br>
To: <a href="mailto:haskell-cafe@haskell.org">haskell-cafe@haskell.org</a><br>
Subject: Re: [Haskell-cafe] question about indentation conventions<br>
<div class="HOEnZb"><div class="h5"><br>
On Mon, Jul 01, 2013 at 05:18:39PM +1200, Richard A. O&#39;Keefe wrote:<br>
&gt;<br>
&gt; It looked pretty explicit to me:<br>
&gt;<br>
&gt;       The golden rule of indentation<br>
&gt;       ...<br>
&gt;       you will do fairly well if you just remember a single rule:<br>
&gt;       Code which is part of some expression should be indented<br>
&gt;       further in than the beginning of that expression (even if<br>
&gt;       the expression is not the leftmost element of the line).<br>
&gt;<br>
&gt; This means for example that<br>
&gt;       f (g x<br>
&gt;           y<br>
&gt;           z)<br>
&gt; is OK but<br>
&gt;       f (g x<br>
&gt;       y z)<br>
&gt; is not.<br>
&gt;<br>
<br>
Sure.  So my first question boils down to which of the two alternatives<br>
below does the community prefer?  (To be clear about the intended<br>
semantics: this is the application of the function f to the arguments x, y,<br>
and z.)<br>
<br>
    f x<br>
    y<br>
    z<br>
<br>
or<br>
<br>
    f x<br>
     y<br>
     z<br>
<br>
Both are correct, in most contexts.<br>
<br>
And then there&#39;s the second question: if the second alternative is<br>
preferable, is there a way to get haskell-mode to do it automatically?  As<br>
it is, it refuses to indent y any farther to the right than in the first<br>
alternative.  I can space it in by hand, and then haskell-mode puts z under<br>
y, but that&#39;s annoying, and it gets in the way of reindenting large regions<br>
of code automatically.<br>
<br>
Richard<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br>
<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</div></div></blockquote></div><br></div>