haskell-style-guide
haskell-style-guide copied to clipboard
Space before record body
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}
?
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.
I invite @tibbe, @mrBliss, @chrisdone.
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.
Either F{...}
or (F {...})
seem reasonable to me objectively speaking. Stylistically I have no preference.
How about F{}
vs (F {})
(constructor-only match)? Spaces and parens add more characters than the original construct has.