Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell indentation style

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.

like image 705
Mohan Avatar asked Dec 16 '12 23:12

Mohan


People also ask

Is Haskell indentation Based?

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.

Is Haskell indentation sensitive?

No, Haskell indentation is not like Python. Haskell is not about indentation levels, it's all about making things line up with other things.


1 Answers

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 :(

like image 156
yairchu Avatar answered Sep 24 '22 20:09

yairchu