Thoughts on auto formatting - haskell-tools/haskell-tools GitHub Wiki
Current formatting rules in this project
Data declarations
- One liner:
data A = A. For data types with one constructor, if it does not exceeds the maximum line length, it is OK. - First break at the equals sign, ident the equals sign to two spaces.
- Multiple constructors: Break before the
|. Ident the|at two spaces. - Parameters: If need to break align the last one on two spaces right to the constructor name.
- Records: Align every start of record to the same column.
- One liner:
data A = A { x :: Int }If there are only one field - Align the comma on the start of the record.
- One liner:
data Expr dom stage
= Var { exprName :: Ann Name dom stage
} -- ^ A variable or a data constructor (@ a @)
| Lit { exprLit :: Ann Literal dom stage }
| InfixApp { exprLhs :: Ann Expr dom stage
, exprOperator :: Ann Operator dom stage
, exprRhs :: Ann Expr dom stage
}
Type signatures
- Break where we gain the most room.
- When breaking on the context, align the context in line with the
::sign. - When breaking on operator (including
->) follow the rules of breaking on operators and align it to two spaces relative to the type.
Expressions
- Break according to precedence. First break the lower-precedence operators. Then the higher precedence operator, after that, break on normal function application.
- When breaking on the same precedence break from right to left.
- Can always break on the
=sign, if this gives more room. - After a break align the next row to two spaces from the start of the expression.
Some reading: haskell-style-guide