[Haskell-cafe] Coding conventions for Haskell?
Andrew Coppin
andrewcoppin at btinternet.com
Mon Sep 27 16:57:01 EDT 2010
On 27/09/2010 02:44 PM, Daniel Fischer wrote:
> On Monday 27 September 2010 14:52:18, Henning Thielemann wrote:
>> data Foo a b =
>> Foo a
>> | Bar b
>> | Foobar a b
>>
>> avoids this, at least for the type name "Foo".
> Tastes vary, but I find that ugly. I much rather have the '=' aligned with
> the '|'.
>
> data Foo a b
> = Foo a
> | Bar b
> | Foobar a b
> deriving (Eq, Ord)
>
> There, that looks good.
Tastes do indeed vary. To me, both of these are incorrect, and the
correct way is
data Foo a b =
Foo a |
Bar b |
Foobar a b
deriving (Eq, Ord)
It honestly annoys me that Haddock disagrees with me on this point...
(It also irritates me that almost all Haskell identifiers are
camel-case, but with an inital lowercase letter. IMHO, the correct thing
to do is use camel-case for identifiers that must begin with an
uppercase letter, and underscores for identifiers that must begin with a
lowercase letter. Of course, my opinion has no effect on the Prelude and
so forth.)
I generally try to structure my code so that all blocks indent by 2
spaces, and the size of indentation never depends on the length of an
identifier. In other words, none of this:
foo x y z = do
thing1 x
thing2 x y
thing3 z
...
Do that a few times and you rapidly end up with lines 300 characters
wide. (!) Instead, I prefer
foo x y z = do
thing1 x
thing2 x y
thing3 z
...
But, as they say, everybody has their own ideas about style. I think the
most important point must surely be that any style is applied
*consistently*...
More information about the Haskell-Cafe
mailing list