When contributing to Snap projects, follow these formatting rules to maintain consistency:
- Line Length: Maximum 80 characters for code.
- Indentation: Use spaces only (tabs are illegal). Use 4 spaces for code blocks. For
where clauses, indent the where keyword by 2 spaces and the definitions within it by an additional 2 spaces. - Blank Lines: Use one blank line between top-level definitions. Do not put blank lines between a type signature and its function definition. In type class instances, use a blank line between functions if the bodies are large.
- Whitespace: Surround binary operators with a single space. Do not insert a space after a lambda.
- Data Declarations: Align constructors in data type definitions. For records, use the following format:
data Person = Person
{ firstName :: String -- ^ First name
, lastName :: String -- ^ Last name
, age :: Int -- ^ Age
} deriving (Eq, Show)
- Pragmas: Place pragmas immediately following the function they apply to. For data type definitions, place the pragma before the type it applies to.
- Export Lists: Format module export lists with indentation and grouping as shown in the examples.
sayHello :: IO ()
sayHello = do
name <- getLine
putStrLn $ greeting name
where
greeting name = "Hello, " ++ name ++ "!"