Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2 space ident and prefixing data constructors #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 43 additions & 41 deletions haskell-style-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Maximum line length is *78 characters*.

#### Code

Tabs are illegal. Use spaces for indenting. Indent your code blocks with *4
Tabs are illegal. Use spaces for indenting. Indent your code blocks with *2
spaces*. Indent the `where` keyword two spaces to set it apart from the rest
of the code and indent the definitions in a `where` clause 2 spaces. Usually we
indent guards two spaces. Some examples:
Expand All @@ -34,8 +34,8 @@ indent guards two spaces. Some examples:
-- | Reads the user's name and prints a greeting to stdout.
sayHello :: IO ()
sayHello = do
name <- getLine
putStrLn $ greeting name
name <- getLine
putStrLn $ greeting name
where
greeting name = "Hello, " ++ name ++ "!"

Expand All @@ -59,14 +59,14 @@ follows:

~~~~~~~~ {.haskell}
reallyLongFunctionName
:: (MonadIO m, MonadSnap m)
=> (Handler LongType LongerType ()
-> Handler LongType LongerType a
-> Handler b v a)
-> (Text -> Text -> Text)
-> Text
-> Text
-> m ()
:: (MonadIO m, MonadSnap m)
=> (Handler LongType LongerType ()
-> Handler LongType LongerType a
-> Handler b v a)
-> (Text -> Text -> Text)
-> Text
-> Text
-> m ()
reallyLongFunctionName = undefined
~~~~~~~~

Expand Down Expand Up @@ -101,21 +101,23 @@ data Tree a = Branch a (Tree a) (Tree a)

For long type names the following formatting is also acceptable:


~~~~~~~~ {.haskell}
data HttpException
= InvalidStatusCode Int
| MissingContentHeader
= HttpException_InvalidStatusCode Int
| HttpException_MissingContentHeader
~~~~~~~~

Data constructors of sum types have to be prefixed with their type constructor,
as shown above.

Format records as follows (but see below for the naming convention):

~~~~~~~~ {.haskell}
data Person = Person
{ firstName :: String -- ^ First name
, lastName :: String -- ^ Last name
, age :: Int -- ^ Age
} deriving (Eq, Show)
{ firstName :: String -- ^ First name
, lastName :: String -- ^ Last name
, age :: Int -- ^ Age
} deriving (Eq, Show)
~~~~~~~~

### Records
Expand All @@ -124,10 +126,10 @@ To prevent record fields clashing as well as creating self-documenting functions

~~~~~~~~ {.haskell}
data AppConfig = AppConfig {
_appConfig_appName :: Text
, _appConfig_log :: Severity
, _appConfig_sqlitePath :: Maybe FilePath
}
_appConfig_appName :: Text
, _appConfig_log :: Severity
, _appConfig_sqlitePath :: Maybe FilePath
}
~~~~~~~~

### Pragmas
Expand All @@ -146,8 +148,8 @@ the type it applies to. Example:

~~~~~~~~ {.haskell}
data Array e = Array
{-# UNPACK #-} !Int
!ByteArray
{-# UNPACK #-} !Int
!ByteArray
~~~~~~~~

### Hanging Lambdas
Expand All @@ -173,15 +175,15 @@ Format export lists as follows:

~~~~~~~~ {.haskell}
module Data.Set
(
-- * The @Set@ type
Set
, empty
, singleton

-- * Querying
, member
) where
(
-- * The @Set@ type
Set
, empty
, singleton

-- * Querying
, member
) where
~~~~~~~~

2. Imports
Expand Down Expand Up @@ -225,17 +227,17 @@ Comment every exported data type. Some examples:
-- state. Returns the number of bytes sent. Applications are
-- responsible for ensuring that all data has been sent.
send
:: Socket -- ^ Connected socket
-> ByteString -- ^ Data to send
-> IO Int -- ^ Bytes sent
:: Socket -- ^ Connected socket
-> ByteString -- ^ Data to send
-> IO Int -- ^ Bytes sent


------------------------------------------------------------------------------
-- | Bla bla bla.
data Person = Person
{ age :: Int -- ^ Age
, name :: String -- ^ First name
}
{ age :: Int -- ^ Age
, name :: String -- ^ First name
}
~~~~~~~~

For functions the documentation should give enough information to
Expand All @@ -248,8 +250,8 @@ comments for data type definitions. Some examples:

~~~~~~~~ {.haskell}
data Parser = Parser
Int -- Current position
ByteString -- Remaining input
Int -- Current position
ByteString -- Remaining input

foo :: Int -> Int
foo n = salt * 32 + 9
Expand Down