Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
f#多行三值表达式_F# - Fatal编程技术网

f#多行三值表达式

f#多行三值表达式,f#,F#,它失败的原因是“此构造已取消种族划分……请将此表达式设置为表示它是列表中的单个元素……”,我这样做 let a = [ 1; 2; 3; if 3 > 2 then 4; else 5; 6 ] 导致编译器告诉我“unmatched”(“)。显然,编译器不喜欢paranthesized多行条件。这是为什么?有什么办法吗 这是一个简单的例子,但在实际使用中,我将使用任意复杂的递归表达式(因此需要将其拆分为多行)

它失败的原因是“此构造已取消种族划分……请将此表达式设置为表示它是列表中的单个元素……”,我这样做

let a = [
    1;
    2;
    3;
    if 3 > 2 then
        4;
    else
        5;
    6
]
导致编译器告诉我“unmatched”(“)。显然,编译器不喜欢paranthesized多行条件。这是为什么?有什么办法吗

这是一个简单的例子,但在实际使用中,我将使用任意复杂的递归表达式(因此需要将其拆分为多行),我不希望分解表达式,并通过列表附加等方式强制执行

编辑: 这项工作:

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

但是比我喜欢的要多一些(5个关键字和4个括号用于一个简单的三元操作!)。搜索更干净的东西将继续

你只需要在添加


不需要分号时使用多行

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

在上面的第一个示例中,在
else
之前有一个
,这是无效的。
let a = [
    1;
    2;
    3;
    (if 3 > 2 then
        4
     else //same column as matching if
        5);
6
]
let a = [
    1
    2
    3
    (if 3 > 2 then 4 else 5)
    6
]