What is the nature of F# exception type
I am learning F# and I found an interesting question. We can use F# type exception
exception MyExpetion of string
However, when we match it, we can use the same syntax as matching a discriminated union. At the same time, it is a System.Exception. How is this done? What is the开发者_运维知识库 type of F# exception? I tried to search but no clear answer is found. Thank you.
You can think of exception types as a sort of "open" discriminated union, where additional constructors for the Exception
type can be added at any time. Therefore, as you might expect, the static type of MyException "test"
is Exception
, and values of type Exception
can be matched against the pattern MyException _
.
精彩评论