Skip to content

Instantly share code, notes, and snippets.

@espio999
Created July 1, 2024 12:46
Show Gist options
  • Save espio999/35b44d2a6876718374ac4efaead845a5 to your computer and use it in GitHub Desktop.
Save espio999/35b44d2a6876718374ac4efaead845a5 to your computer and use it in GitHub Desktop.
F# pattern matching - type test
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