I just discovered that this
foo = case ((), ()) of
( ()
, () ) -> ()
fails with
/tmp/wtmpf-file11080.hs:3:8:
parse error (possibly incorrect indentation or mismatched brackets)
This can be made to work by indenting the second line of the pattern
foo = case ((), ()) of
( ()
, () ) -> ()
but this feels inconsistent with my usual style, especially in
bar = case ( some lengthy :: Complicated typed expression
, another also lengthy :: Expression with (Other types) ) of
( Complicated (Pattern match) to (unwrap)
, Expression that's (Again not so short) ) -> the Rest of my Code
How should the above be rewritten / formatted to look most consistent?
By the indentation rules, the code
foo = case ((), ()) of
( ()
, () ) -> ()
is desugared to
foo = case ((), ()) of
{ ( ()
; , () ) -> ()
}
which is a case
with two branches, the first one being a syntax error.
I would recommend the following style instead:
foo = case ((), ()) of
(( ()
, () )) -> ()
or even (not extremely elegant, though)
foo = case ((), ()) of
_@( ()
, () ) -> ()
You could also just rewrite the pattern match as
(Complicated (Pattern match) to (unwrap),
Expression that's (Again not so short)) -> the Rest of my Code
I know it's incompatible with your style, but I think there is no real reason to use that style for tuples (aside from consistency).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With