I have this code to raise an error when file doesn't exist.
if !File.Exists(doFile) then
printfn "doFile doesn't exist %s" doFile; failwith "quit"
However, I got this error. What's wrong?
error FS0001: This expression was expected to have type
bool ref
but here has type
bool
The !
operator has a special meaning in F#, its defined as:
type 'a ref { Contents : 'a }
let (!) (x : ref 'a) = x.Contents
You're getting the error because the !
operator expects a bool ref
, but you passed it a bool
.
Use the not
function instead:
if not(File.Exists(doFile)) then
printfn "doFile doesn't exist %s" doFile; failwith "quit"
in F# ! is not a NOT, it's a referencing operatior, so to say not, you need to use the not function, something like if not <| File.Exists....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With