Haskell Programming Guidelines

複数人でHaskellを使うときにゴルフコードへの誘惑をいかに断つかってのは最もだなあと思う。別にHaskellに限った話ではないが。

Programming guidelines – HaskellWiki:

http://www.haskell.org/haskellwiki/Programming_guidelines

All Haskell source files start with a haddock header of the form:

{- |
Module      :  <File name or $Header$ to be replaced automatically>
Description :  <optional short text displayed on contents page>
Copyright   :  (c) <Authors or Affiliations>
License     :  <license>

Maintainer  :  <email>
Stability   :  unstable | experimental | provisional | stable | frozen
Portability :  portable | non-portable (<reason>)

<module description starting at first column>
-}

Bad:

case foo of Foo -> "Foo"
         Bar -> "Bar"

Good:

case  of
       Foo -> "Foo"
       Bar -> "Bar"

Not always nice:

longFunctionName (Foo: _ : _) = e1
longFunctionName (Bar: _) = e2

Better:

longFunctionName arg = case arg of
       Foo : _ : _ -> e1
       Bar : _ -> e2
       _ -> error "ProgrammingGuidelines.longFunctionName"

Bad (to handle arguments in sync):

data Mode f p = Box f p | Diamond f p

Good (to handle arguments only once):

data BoxOrDiamond = Box | Diamond

 data Mode f p = Mode BoxOrDiamond f p

Consider (bad):

data Tuple a b = Tuple a b | Undefined

versus (better):

data Tuple a b = Tuple a b

and using:

Maybe (Tuple a b)
Written on January 20, 2011