[Haskell-cafe] Re: Is 78 characters still a good option? Was:
breaking too long lines
Christian.Maeder at dfki.de
Mon Apr 27 10:15:49 EDT 2009
Richard O'Keefe wrote:
> On 25 Apr 2009, at 8:59 pm, Miguel Mitrofanov wrote:
>> Something like
>> newtype MyCoolMonad = MyCoolMonad (FirstTransformer (SecondTransformer
>> (ThirdTransformer Whatever))) deriving (Functor, Monad, FirstClass,
>> SecondClass, ThirdClass, SomeOtherClass)
> For what it's worth, my personal Haskell style lines up
> data T
> = C1 ...
> | ...
> | Cn ...
> deriving (...)
This has the clear advantage that indentation does not depend on the
length of the type name as in the quite typical layout of Xiao-Yong Jin:
> so I'd have this as
> newtype MyCoolMonad
> = MyCoolMonad (FirstTransformer (SecondTransformer
> (ThirdTransformer Whatever)))
> deriving (Functor, Monad, FirstClass, SecondClass, ThirdClass,
> where the longest line is 86 columns.
(which is still too long as my reply-wrap proofs.)
However, indenting by 3 or 6 characters depending on "data" or "newtype"
is also a bit arbitrary. Consider:
newtype MyCoolMonad =
(SecondTransformer (ThirdTransformer Whatever)))
( Functor, Monad, FirstClass, SecondClass, ThirdClass
Either all alternatives fit on one line or they go on separate lines
each. The same should apply to all components of one alternative.
Additionally, as above, a long type-application may need to be broken
over several lines. (Breaking before "=" and having "=" above "|" looks
Pretty-printing a comma-separated list (following deriving) is an extra
subject with a couple of variations:
Putting commas in the front, better indicates the continuation, but the
extra space following the open bracket "(" looks a bit odd. (Surely one
could also leave a space before the closing bracket, although I wouldn't
like spaces around all brackets.)
(Functor, Monad, FirstClass, SecondClass, ThirdClass,
has the disadvantage, that the second line is only indented by one
character (relative to the previous one), but intending further (+1 or
+3 or even one less) is an alternative.
(I'm no friend of putting the closing bracket on a separate line in the
same column as the opening one. Too easily such indentations are messed
More information about the Haskell-Cafe