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.
Haskell relies on indentation to reduce the verbosity of your code. Despite some complexity in practice, there are really only a couple fundamental layout rules.
No, Haskell indentation is not like Python. Haskell is not about indentation levels, it's all about making things line up with other things.
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 :(
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With