File F的文件检查代码#
当文件不存在时,我会使用此代码引发错误File F的文件检查代码#,file,f#,File,F#,当文件不存在时,我会使用此代码引发错误 if !File.Exists(doFile) then printfn "doFile doesn't exist %s" doFile; failwith "quit" 然而,我得到了这个错误。怎么了 error FS0001: This expression was expected to have type bool ref but here has type bool 用F#!不是not,它是一个引用运算符,所
if !File.Exists(doFile) then
printfn "doFile doesn't exist %s" doFile; failwith "quit"
然而,我得到了这个错误。怎么了
error FS0001: This expression was expected to have type
bool ref
but here has type
bool
用F#!不是not,它是一个引用运算符,所以说not,您需要使用not函数,类似于
if notthe
运算符在F#中有特殊含义,其定义如下:
type 'a ref { Contents : 'a }
let (!) (x : ref 'a) = x.Contents
您得到错误是因为
运算符需要一个bool ref
,但您传递了一个bool
请改用而不是功能:
if not(File.Exists(doFile)) then
printfn "doFile doesn't exist %s" doFile; failwith "quit"
这是一个很好的例子,说明使用反向管道可以使事情更具可读性。