Editor agnosticism in haskell examples

Nov 27, 2006 15:50

pozorvlak recently discovered a bit of a gotcha in writing haskell examples:

If I'm in emacs, and I write this:

tick = do n <- get; put (n+1); return n;

on three lines, it comes out like this:

tick = do n <- get
put (n+1)
return n
This is because emacs has a particularly smart indent mode - it notices the "do", and realises that I ( Read more... )

docs, haskell, code

Leave a comment

Comments 3

do indenting anonymous November 28 2006, 02:37:33 UTC
If you're not happy about the extra line note the vim indentation file here. It gives vim at least a passing familiarity with do blocks (among other things), which means that if you do:

tick = do n <- get
And press enter, the auto-indent will align with the n, as it should. Seems to require vim7, though.

It's no comparison to haskell-mode for emacs, but it's better than default vim indentation. Of course, your suggestion works as well. :)

Reply

Re: do indenting totherme November 28 2006, 10:02:00 UTC
That sounds very cool - thanks, I'll give it a try :)

I would still like to argue though, that when writing code that's primarily intended to be read rather than run - particularly by beginners (so, library docs and particularly tutorials), the extra line is worthwhile.

This is because I think that beginners can't be expected to fully understand haskell indentation rules (at least in this much detail) right from the start. I also think it's unreasonable to expect them to be using one of vim or emacs.

When I'm writing example code, I'd like a beginner to be able to naively copy-type it into notepad, and have it work first time.

Reply


Thank you! anonymous April 4 2008, 20:30:03 UTC
I'm just starting Haskell, and that's the first solid piece of formatting 'rule' I've come across. In fact, it just got me past where I was hung up in "Yet Another Haskell Tutorial". I found your post while searching for some guidelines.

Thanks again!

Reply


Leave a comment

Up