[Haskell-cafe] Re: Coding conventions for Haskell?

Victor Nazarov asviraspossible at gmail.com
Mon Sep 27 10:52:39 EDT 2010


On Mon, Sep 27, 2010 at 8:20 AM, Richard O'Keefe <ok at cs.otago.ac.nz> wrote:
>
> On Sep 27, 2010, at 5:31 AM, Maciej Piechotka wrote:
>> May I ask clarification about formatting (according to your convention)
>>
>> doSomething :: (a -> a -> a) -> a -> a -> a
>> doSomething f x = f y y
>>                  where y = f x x
>>
>> i.e. single line function+where
>
> There is a meta-rule that I use for indentation in a wide range of
> languages:  where the line breaks are may depend on identifier spelling,
> but what the indentation is should not.
>
> In Haskell I sometimes violate that, but I usually end up regretting it.
>

+1

I use the same rule. My style looks like this.

module Module
  where ( FancyType (..)
        , main
        )

data FancyType a b
  = FirstConstructor a
  | SecondConstructor b
  deriving (Show)

f a b
  | a > 0 = FisrtConstructor a
  | otherwise = SecondConstructor g
  where g = h b
        h = id

main =
  do putStrLn hello
     putStrLn . concat
       [ hello
       , show (f 25 1)
       ]
     flip mapM_ [1..100] $ \n ->
       do print n
          putStrLn hello
  where hello = "Hello"

I allways use spaces without tabs and allways use camelCase.

-- 
Victor Nazarov


More information about the Haskell-Cafe mailing list