问题
I am trying to check if a variable is of a certain type like so:
let s = "abc"
let isString = s :? string
but in F# interactive, I get the following error:
error FS0016: The type 'string' does not have any proper subtypes and cannot be used as the source of a type test or runtime coercion.
Why is this happening? I expect isString to be a bool.
回答1:
Because you are trying with a sealed type.
Try instead this:
let s = box "abc"
let isString = s :? string
There is no point in doing this coercion tests with sealed types since they can't have any subtype and that's what the error message is telling you.
来源:https://stackoverflow.com/questions/39452303/f-why-cant-i-use-the-operator-in-f-interactive