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