tibbe / haskell-style-guide

A style guide for Haskell code.
957 stars 75 forks source link

Space before record body #21

Open cblp opened 8 years ago

cblp commented 8 years ago

Should the space between record constructor or updated expression and record field list exist?

data Rec type1 = Rec{field1 :: type1, field2 :: Type2}
f x@Rec{field1} = x{field2 = field1}

or

data Rec type1 = Rec {field1 :: type1, field2 :: Type2}
f x@Rec {field1} = x {field2 = field1}

?

cblp commented 8 years ago

My personal voice contra the space.

Consider expression f x {...} or pattern F X {...}. They look like three space-delimited items, when are actually just two-item expressions. When I write f x{...} or F X{...} semantics is clear.

cblp commented 8 years ago

I invite @tibbe, @mrBliss, @chrisdone.

tibbe commented 8 years ago

I believe the common practice is to use a space but use parenthesis (or sometimes newlines, for big records) for clarity e.g. f (x {...}).

In general I try to capture common practice in the style guide. Perhaps you can check what popular packages (like aeson etc.) do.

chrisdone commented 8 years ago

Either F{...} or (F {...}) seem reasonable to me objectively speaking. Stylistically I have no preference.

dpwiz commented 8 years ago

How about F{} vs (F {}) (constructor-only match)? Spaces and parens add more characters than the original construct has.