[Haskell-cafe] Coding conventions for Haskell?

Henning Thielemann schlepptop at henning-thielemann.de
Mon Sep 27 08:52:18 EDT 2010


Alexander Solla schrieb:

> I used a modified version of the "best practices" described by the Perl
> people for Perl code.  "Like things go under like things" is the most
> important rule to follow.  This rule, in other words, is a convention to
> make your code as "tabular" as possible.  Also, most expressions have an
> "outermost" connective.  I tend to align them:
> 
> Consider:
> 
> data Foo a b = Foo    a
>              | Bar      b
>              | Foobar a b
> 
> That's not so nice looking now, but consider what happens when you have
> four or five arguments:

This indentation relies on Foo remaining Foo in the future. If you alter
Foo then you have to move the block of constructors as well. This gives
line changes in a versioning system where nothing actually has changed.
The style

data Foo a b =
     Foo    a
   | Bar      b
   | Foobar a b

avoids this, at least for the type name "Foo".


More information about the Haskell-Cafe mailing list