Sol*_*lma 2 f# compiler-errors visual-studio f#-interactive
我有几百行的代码.它的许多小块具有以下结构:
let soa =
election
|> Series.observations
printfn "%A" <| soa
Run Code Online (Sandbox Code Playgroud)
经常发生两件事:
1)神秘地将最后一行改为:
printfn "%A" <|
Run Code Online (Sandbox Code Playgroud)
以便上面的代码和后面的内容成为
let soa =
election
|> Series.observations
printfn "%A" <|
let sls =
election
|> Series.sample (seq ["Party A"; "Party R"])
printfn "%A" <| sls
Run Code Online (Sandbox Code Playgroud)
这发生在编辑器中编辑文件的上面数百行.
2)发生这种情况时F# Interactive不会标记错误.不会生成任何错误消息.但是,如果我尝试访问,sls我会收到消息:
error FS0039: The value or constructor 'sls' is not defined.
有关为什么在编辑器中删除了一些代码的想法?(这种情况经常发生)
为什么不F# Interactive发出错误消息?
第二个let块被解释为前面的参数printfn,因为作为运算符的管道为偏移规则提供了一个例外:运算符的第二个参数不必缩进到比第一个参数更远的位置.而且由于第二个let区块不在顶层,而是printfn参数的一部分,因此其定义不会在外部访问.
我们来试试吧:
let f x = x+1
// Normal application
f 5
// Complex expression as argument
f (5+6)
// Let-expression as argument
f (let x = 5 in x + 6)
// Replacing the `in` with a newline
f ( let x = 5
x + 6 )
// Replacing parentheses with pipe
f <|
let x = 5
x + 6
// Operators (of which the pipe is one) have an exception to the offset rule.
// This is done to support flows like this:
[1;2;3] |>
List.map ((+) 1) |>
List.toArray
// Applying this exception to the `f` + `let` expression:
f <|
let x = 5
x + 6
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
49 次 |
| 最近记录: |