[Haskell-cafe] Code layout in Emacs' haskell-mode

David House dmhouse at gmail.com
Mon May 14 12:21:06 EDT 2007


On 14/05/07, Christopher L Conway <cconway at cs.nyu.edu> wrote:
> For example, here's the "Hello, world" example from the tutorial, with
> the indentation induced by pounding Tab in haskell-mode.
>
> test.hs:
> module Test
>     where
>
>       import IO
>
> main = do
>   putStrLn "Hello, world"
>
> Prelude> :l test
> [1 of 1] Compiling Test             ( test.hs, interpreted )

Are you learning from YAHT, by any chance? That's the only place I've
seen the weird convention of placing the 'where' of the 'module X' bit
on a separate line. By far the most common convention in normal
Haskell is to do as follows:

module X where

[rest of module]

Things should work better if you follow this convention. What you
describe still sounds like a bug, though.

> Again, if I hit tab on the "then" or "else" lines, emacs reports "Sole
> indentation". But if I manually change the indentation, it works.

This too looks like a bug. As you remark, if statements within
do-blocks have different indentation to everywhere else, confusingly.

> Does haskell-mode support code layout? Are there conventions I need to
> know about to make it behave properly? I have haskell-mode version
> 2.1-1 installed from the Ubuntu feisty repository.

You should install 2.3 from the haskell-mode page [1]. Isaac Jones,
maintainer of the Debian haskell-mode package has been contacted in
order to get the latest version in the Debian repository, so it should
happen soon, but in the mean time you could download and install the
latest version yourself. It features quite a few bugfixes and new
features that I imagine are documented on the aforementioned page.

haskell-mode's indentation engine is still one thing I'm yet to get my
head around, and its being written in Emacs Lisp doesn't help the
matter! Still, it's on my todo list.

[1]: http://haskell.org/haskell-mode

-- 
-David House, dmhouse at gmail.com


More information about the Haskell-Cafe mailing list