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
File F的文件检查代码#_File_F# - Fatal编程技术网

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"

这是一个很好的例子,说明使用反向管道可以使事情更具可读性。