Why is this a syntax error for matches in the case of matching strings without additional indentation, and what recommended style is bypassed?

I just discovered that this

foo = case ((), ()) of ( () , () ) -> () 

not working with

 /tmp/wtmpf-file11080.hs:3:8: parse error (possibly incorrect indentation or mismatched brackets) 

This can be done by indenting the second line of the pattern.

 foo = case ((), ()) of ( () , () ) -> () 

but it seems incompatible 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 (Again not so short) ) -> the Rest of my Code 

How should this be rewritten / formatted to look most consistent?

+5
source share
2 answers

Indent rules

 foo = case ((), ()) of ( () , () ) -> () 

exempted

 foo = case ((), ()) of { ( () ; , () ) -> () } 

which is a case with two branches, the first of which is a syntax error.

Instead, I recommend the following style:

 foo = case ((), ()) of (( () , () )) -> () 

or even (not very elegant though)

 foo = case ((), ()) of _@ ( () , () ) -> () 
+7
source

You can also just rewrite the pattern match as

  (Complicated (Pattern match) to (unwrap), Expression that (Again not so short)) -> the Rest of my Code 

I know that this is incompatible with your style, but I think there is no real reason to use this style for tuples (other than sequence).

+1
source

Source: https://habr.com/ru/post/1260715/


All Articles