Created
July 1, 2024 12:46
-
-
Save espio999/35b44d2a6876718374ac4efaead845a5 to your computer and use it in GitHub Desktop.
F# pattern matching - type test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type A() = class end | |
type B() = inherit A() | |
type C() = inherit A() | |
let evaluation (obj: A) = | |
match obj with | |
| :? B -> "It's a B" | |
| :? C -> "It's a C" | |
| :? A -> "It's a A" | |
| _ -> "nothing" | |
let a = new A() | |
let b = new B() | |
let c = new C() | |
printfn "%s" (evaluation a) | |
printfn "%s" (evaluation b) | |
printfn "%s" (evaluation c) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment