Hi Christopher,<br><br>I have also noticed that haskell-mode (and indeed Haskell) can be finicky sometimes.&nbsp;&nbsp;I usually put &quot;module [Name] where&quot; all on the same line and leave &quot;import&quot;s on the left margin, so I hadn&#39;t experienced the first problem you mentioned.&nbsp;&nbsp;However, I do notice that if I re-arrange your second example so that &quot;do&quot; and the first &quot;putStrLn&quot; are on the same line, emacs offers the following indentation:
<br><br><span style="font-family: courier new,monospace;">module Num where</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">import IO</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">main = do putStrLn &quot;Enter a number: &quot;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; inp &lt;- getLine</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; let n = read inp</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if n == 0</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; then putStrLn &quot;Zero&quot;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else putStrLn &quot;NotZero&quot;</span><br><br>(that&#39;s with all the expressions in the do block lining up vertically, if that doesn&#39;t show up in a fixed-width font), it works!&nbsp; I would think that your original indentation gave an error in that GHC would see &quot;then&quot; and &quot;else&quot; and assume they were new expressions, but then I would expect that this would have the same problem.&nbsp; If anyone can shed some light on this, that would be nice.
<br><br>Thanks,<br>Nick Meyer<br><a href="mailto:npmeyer@syr.edu">npmeyer@syr.edu</a><br><br>On 5/14/07, Christopher L Conway &lt;<a href="mailto:cconway@cs.nyu.edu">cconway@cs.nyu.edu</a>&gt; wrote:<br>&gt; I am new to Haskell---and also to languages with the off-side
<br>&gt; rule--and working my way through Hal Daume&#39;s tutorial. I&#39;m a little<br>&gt; confused by the support for code layout in Emacs&#39; haskell-mode. Is it<br>&gt; buggy, or am I doing something wrong.<br>&gt; 
<br>&gt; For example, here&#39;s the &quot;Hello, world&quot; example from the tutorial, with<br>&gt; the indentation induced by pounding Tab in haskell-mode.<br>&gt; <br>&gt; test.hs:<br>&gt; module Test<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; where
<br>&gt; <br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; import IO<br>&gt; <br>&gt; main = do<br>&gt;&nbsp;&nbsp; putStrLn &quot;Hello, world&quot;<br>&gt; <br>&gt; Prelude&gt; :l test<br>&gt; [1 of 1] Compiling Test&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ( test.hs, interpreted )<br>&gt; <br>
&gt; test.hs:12:0: parse error on input `main&#39;<br>&gt; <br>&gt; In emacs, every line but the one with &quot;where&quot; reports &quot;Sole<br>&gt; indentation&quot;. With &quot;where&quot;, I have the option of having it flush left
<br>&gt; or indented four spaces; &quot;import&quot; wants to be two spaces in from<br>&gt; &quot;where&quot;. Moving where doesn&#39;t change the error. But if I manually move<br>&gt; import flush left (which is the way it&#39;s shown in the tutorial, BTW):
<br>&gt; <br>&gt; module Test<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; where<br>&gt; <br>&gt; import IO<br>&gt; <br>&gt; main = do<br>&gt;&nbsp;&nbsp; putStrLn &quot;Hello, world&quot;<br>&gt; <br>&gt; Prelude&gt; :l test<br>&gt; [1 of 1] Compiling Test&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ( 
test.hs, interpreted )<br>&gt; Ok, modules loaded: Test.<br>&gt; <br>&gt; I have a similar problem with the layout of if-then-else...<br>&gt; <br>&gt; num.hs:<br>&gt; module Num<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; where<br>&gt; <br>&gt; import IO
<br>&gt; <br>&gt; main = do<br>&gt;&nbsp;&nbsp; putStrLn &quot;Enter a number: &quot;<br>&gt;&nbsp;&nbsp; inp &lt;- getLine<br>&gt;&nbsp;&nbsp; let n = read inp<br>&gt;&nbsp;&nbsp; if n == 0<br>&gt;&nbsp;&nbsp; then putStrLn &quot;Zero&quot;<br>&gt;&nbsp;&nbsp; else putStrLn &quot;NotZero&quot;
<br>&gt; <br>&gt; Prelude&gt; :l num<br>&gt; [1 of 1] Compiling Num&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;( num.hs, interpreted )<br>&gt; <br>&gt; num.hs:11:2: parse error (possibly incorrect indentation)<br>&gt; <br>&gt; Again, if I hit tab on the &quot;then&quot; or &quot;else&quot; lines, emacs reports &quot;Sole
<br>&gt; indentation&quot;. But if I manually change the indentation, it works.<br>&gt; <br>&gt; module Num<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; where<br>&gt; <br>&gt; import IO<br>&gt; <br>&gt; main = do<br>&gt;&nbsp;&nbsp; putStrLn &quot;Enter a number: &quot;
<br>&gt;&nbsp;&nbsp; inp &lt;- getLine<br>&gt;&nbsp;&nbsp; let n = read inp<br>&gt;&nbsp;&nbsp; if n == 0<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;then putStrLn &quot;Zero&quot;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else putStrLn &quot;NotZero&quot;<br>&gt; <br>&gt; Prelude&gt; :l num<br>&gt; [1 of 1] Compiling Num&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;( 
num.hs, interpreted )<br>&gt; Ok, modules loaded: Num.<br>&gt; <br>&gt; This is particularly weird because if-then-else doesn&#39;t always act this way:<br>&gt; <br>&gt; exp.hs:<br>&gt; module Exp<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; where<br>&gt; 
<br>&gt; my_exponent a n =<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; if n == 0<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; then 1<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; else a * my_exponent a (n-1)<br>&gt; <br>&gt; Prelude&gt; :l exp<br>&gt; [1 of 1] Compiling Exp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;( exp.hs, interpreted )<br>&gt; Ok, modules loaded: Exp.
<br>&gt; <br>&gt; I suppose this might have something to do with the do-notation...<br>&gt; <br>&gt; Does haskell-mode support code layout? Are there conventions I need to<br>&gt; know about to make it behave properly? I have haskell-mode version
<br>&gt; 2.1-1 installed from the Ubuntu feisty repository.<br>&gt; <br>&gt; Thanks,<br>&gt; Chris<br>&gt; _______________________________________________<br>&gt; Haskell-Cafe mailing list<br>&gt; <a href="mailto:Haskell-Cafe@haskell.org">
Haskell-Cafe@haskell.org</a><br>&gt; <a href="http://www.haskell.org/mailman/listinfo/haskell-cafe">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>&gt; <br><br>