Skip to content

Code style guide

Irakli Safareli edited this page Jul 16, 2019 · 1 revision

data definitions with records

data Foo = Foo
  { fooCat :: Cat
  , fooDog :: Dog
  }

data definitions with sum types

data Foo
  = Foo Bool String
  | Biz Int Word32

data definitions with records in sum types

data Foo
  = Foo
      { fooDing :: Ding
      , fooDong :: Dong
      }
  | Biz
      { bizDing :: Ding
      , bizDong :: Dong
      }

data definitions with product types

data Foo = Foo Bool Int

data Biz = Biz
  SomeLongNameOfType
  SomeLongNameOfType2

constructors applied to records

Foo
  { fooCat = fooCat
  , fooDog = fooDog
  }

where clauses

foo =
  f ...
  where
    f = ...

let clauses

foo =
  let 
    f = ...
  in
    f ...

function signatures

f :: Int -> Bool

ggggg ::
  ( Eq a
  , Show b
  , ShowFooBar b
  )
  => SomeLongNameOfType2
  -> SomeLongNameOfType2
  -> b
  -> a
  -> SomeLongNameOfType2

h
  :: SomeLongNameOfType2
  -> SomeLongNameOfType2
  -> b
  -> a
  -> SomeLongNameOfType2

class instances

instance SomeClass Foo where singleFunction = genericSomeClass

instance OtherClass Foo where
  otherFunctionWithNonGenericDefinition = ....