haskell-style-guide icon indicating copy to clipboard operation
haskell-style-guide copied to clipboard

Space before record body

Open cblp opened this issue 8 years ago • 5 comments

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 avatar Sep 01 '16 17:09 cblp

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 avatar Sep 01 '16 17:09 cblp

I invite @tibbe, @mrBliss, @chrisdone.

cblp avatar Sep 01 '16 17:09 cblp

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.

tibbe avatar Sep 01 '16 22:09 tibbe

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

chrisdone avatar Sep 02 '16 08:09 chrisdone

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

dpwiz avatar Sep 02 '16 08:09 dpwiz