我有这个代码在文件不存在时引发错误.
if !File.Exists(doFile) then
printfn "doFile doesn't exist %s" doFile; failwith "quit"
Run Code Online (Sandbox Code Playgroud)
但是,我收到了这个错误.怎么了?
error FS0001: This expression was expected to have type
bool ref
but here has type
bool
Run Code Online (Sandbox Code Playgroud)
Jul*_*iet 17
该!运营商在F#有特殊的意义,它的定义为:
type 'a ref { Contents : 'a }
let (!) (x : ref 'a) = x.Contents
Run Code Online (Sandbox Code Playgroud)
你得到错误是因为!操作员期望a bool ref,但是你传递了它bool.
请改用此not功能:
if not(File.Exists(doFile)) then
printfn "doFile doesn't exist %s" doFile; failwith "quit"
Run Code Online (Sandbox Code Playgroud)
在F#中!不是NOT,它是一个引用操作符,所以要说不是,你需要使用not函数,比如if not <| File.Exists....
| 归档时间: |
|
| 查看次数: |
1939 次 |
| 最近记录: |