[Haskell-cafe] Coding conventions for Haskell?

Daniel Fischer daniel.is.fischer at web.de
Mon Sep 27 13:56:43 EDT 2010


On Monday 27 September 2010 18:09:08, Evan Laforge wrote:
> > data Foo a b
> >    = Foo      a
> >    | Bar        b
> >    | Foobar  a b
> >      deriving (Eq, Ord)
> >
> > There, that looks good.
>
> There is a trap if you do a similar thing with records:
>
> data Foo = Foo
>   { a :: Int
>   , b :: Int
>   }
>
> If you use '-- |' style haddock it can't go on 'a'.  Since I tend to
> want to put '-- |' on every field, I have to put the '{' on the
> previous line.

Hm, yes. I always use '-- ^' haddock comments for record fields, so that 
didn't occur to me.

>
> As for other stuff, I don't like the vertical lining up thing.  It's

I haven't tried it yet. I think aligning corresponding fields has 
advantages - it makes it rather obvious to see which constructor uses which 
parameter types in many cases.
On the other hand, with many fields you get a very scattered picture if 
some constructors only have few. That looks ugly and isn't easy to take in 
at a glance.
I don't think I'll adopt it, but I plan to try it out.

> too much work to type in, causes too much realigning when the top line
> changes, sometimes causes things to get too far right,

Yep

> and breaks entirely with proportional fonts.

Not relevant for me, when looking at Haskell or Python code, I value my 
fixed-width font, it just looks too weird in proportional fonts.

> A plain indent as advocated above avoids all those problems.



More information about the Haskell-Cafe mailing list