I find that I'm often inconsistent about how much I indent things, where I put in new lines, etc.. Are there official or widely followed guidelines for how one ought to layout whitespace in Haskell? Note that I'm not asking what's legal; I'm asking what's good practice, along the lines of Good Haskell coding style of if/else control block? , but much more generally. I'm particularly keen on knowing what people do with do-blocks, let-blocks, where-blocks and case statements, especially when such things are nested in each other or inside several function definitions.
Asked
Active
Viewed 1,753 times
6
-
1[Indentation](http://en.wikibooks.org/wiki/Haskell/Indentation) on Wikibooks should cover what you're looking for. – David Cain Dec 16 '12 at 23:42
-
13[Here's a good set of general Haskell style guidelines, including indentation](https://github.com/tibbe/haskell-style-guide/blob/master/haskell-style.md). – hammar Dec 16 '12 at 23:47
-
1@David: that's about what's legal, not what's good practice. – Mohan Dec 16 '12 at 23:48
-
I would have posted hammar’s comment as an answer if it were not already a comment. SE needs a „promote comment to answer vote“ button next to comments. – Joachim Breitner Dec 17 '12 at 22:27
-
[This](http://stackoverflow.com/questions/6398996/good-haskell-source-to-read-and-learn-from) question might be interesting to you. – Laar Dec 19 '12 at 18:15
1 Answers
1
A small nitpick if I may.
I mostly like hammar's linked guideline. But, I really dislike this style:
send :: Socket
-> ByteString
-> IO Int
I much prefer
send ::
Socket ->
ByteString ->
IO Int
In the latter style, the arguments and the result look different (the arguments have ->
s after them).
I like this better. People may disagree and it's mostly just matters of personal taste. Sadly afaik haddock seems to only support the former style :(

yairchu
- 23,680
- 7
- 69
- 109
-
1I also wonder if the 80 character per line rule is there in hindsight of people that need to punch their haskell source on cards? – Ingo Dec 18 '12 at 14:41
-
@Ingo In my opinion, column limits use space better. I typically put several columns of text side-by-side on screen. – Heatsink Dec 18 '12 at 14:58
-
-
2I dislike both styles equally, but I've yet to find a better option. When possible, I simply avoid type signatures too wide for one line. – C. A. McCann Dec 18 '12 at 15:01
-
Practical concerns on shared code make the first style preferable. When reviewing signature changes in the second style, particularly changes that add new parameters to the end of a signature, more lines than necessary appear in the diff. I prefer the first style and it is consistent with the preferred style for lists, data declarations, module exports, and several other Haskell constructs. That said, I agree in part in that I also prefer not to wrap signatures at all (which throws away my whole merging argument) ;) – Alain O'Dea Jan 17 '14 at 02:16