F # multiline ternary expressions

let a = [ 1; 2; 3; if 3 > 2 then 4; else 5; 6 ] 

What fails with "this construct corrupts ...... Paranthesize is an expression to indicate that it is a separate list item ..." what I do is

 let a = [ 1; 2; 3; (if 3 > 2 then 4 else 5); 6 ] 

makes the compiler tell me "unsurpassed" ("". Obviously, the compiler does not like conditional binding with binding to a multi-line line. Why is this? And is there any way?

This is a trivial case, but in actual use I will have arbitrarily complex recursive expressions (so I need to break it into several lines), and I do not want to decompose this expression and do it strictly through list-appending and what not.

EDIT: this works:

 let a = [ 1; 2; 3; if 3 > 2 then yield( 4 )else yield( 5); 6 ] 

but somewhat more verbose than I would prefer (5 keywords and 4 brackets for a simple triple operation!). The search for something cleaner continues

+4
source share
2 answers

You just need to back out else , as to the left of if , after adding (

 let a = [ 1; 2; 3; (if 3 > 2 then 4 else //same column as matching if 5); 6 ] 
+6
source

A multiline line when a semicolon is not required.

 let a = [ 1 2 3 (if 3 > 2 then 4 else 5) 6 ] 
+2
source

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


All Articles