Table of Contents

Coding conventions

General rules

Line length

For source code, the line length is up to 80 characters, at the maximum.

For comments code, the line length is up to 160 characters, at the maximum.

Indentation

Binding names in pattern and functions

Abbreviation Meaning
Char Character
In Input
Out Output
Pos Position

Example outFromCmpOut with function name using custom prefix out to indicate the resulting custom type:

outFromCmpOut :: (ComposableOutput usrSym) -> (Output usrSym)

Example symTree as matched pattern name using custom prefix sym to indicate the custom type:

outFromCmpOut (CmpOut (CmpValid symTree _ _) _) = Valid symTree

Example lErr as matched name using standard prefix l plus err to indicate the custom list type combined with custom prefix err:

outFromCmpOut (CmpOut (CmpInvalid lerr) _) = Invalid lerr

Standard prefixes

Type or type class Prefix Examples
a x xMax for a maximum value of an arbitrary type
Num ⇒ n nRowPos for the line number of a row
Int n or nj njExp for the exponent in a power operation
Integer n or ni niLength to provide the length of a list
Double n or nd ndDegreesCentigrade to indicate a temperature
Float n or nf nfVolt to indicate a voltage
Bool is, do, does, are, has isHead, doAllOutFileExist, areAllOpen, hasBeenUpdated
[<a>] l<a> lerr to match with list of elements of a data type that is defined with prefix err
(<a>,<b>) tpl, tpl2 tpl2 just a tuple with two elements
(<a>,<b>,<3>) tpl, tpl3 tpl just a tuple
(<elem>:lr<elem>) none, and lr (ch:lrch) for a list of Char
l<elem>@(<elem>:lr<elem>) l, none, and lr lch@(ch:lrch) for a list of Char
Char ch chRead for a charater to read
String, [Char] s, lch sStream record name to get a string from stream
Maybe <a> m<a> mch for a binding of type Maybe Char
Either <e> <n> e<n> en or eni for a binding of type Either String Integer
IO io io for a function result type IO () or ios for a function result type IO String
Word8 w8 w8FromChar converts char to a Word8 value
Word16 w16
Word32 w32
Word64 w64
*→* f fConvert to name a function as parameter or fioWrite for a function that writes to IO ()
Module Prefix Import directive
Control.Exception.Base Ex import qualified Control.Exception.Base as Ex
Data.Bits Bts import qualified Data.Bits as Bts
Data.ByteString BS import qualified Data.ByteString as BS
Data.Char Chr import qualified Data.Char as Chr
Data.List Lst import qualified Data.List as Lst
Data.Time Tm import qualified Data.Time as Tm
Data.Word Wrd import qualified Data.Word as Wrd
Debug.Trace Dbg import qualified Debug.Trace as Dbg
Numeric Nm import qualified Numeric as Nm
System.Directory Dir import qualified System.Directory as Dir
System.IO SIo import qualified System.IO as SIo

Custom prefixes

Outline of a module

Module description

GHC extensions and options

Module declaration and export list

Sections

Class declaration

Instance declaration

Data type declaration

Sum type

Product type

Mixed type

Record syntax

In sums of algebraic types: "dangerous"

NOTE: Usage of record syntax in sums of algebraic types is “dangerous”. They can lead to runtime errors. Don't use them! See the example below - went wrong.

Rather use the safe alternative below.

Function declaration