F# equivalent of `is` keyword in C#?

前端 未结 3 1599
心在旅途
心在旅途 2020-12-10 12:18

My first F# day. If I have this:

let cat = Animal()

Now how do I check at later stage if cat is Animal

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-10 12:38

    For demonstration only (don't define an is function):

    let is<'T> (x: obj) = x :? 'T
    
    type Animal() = class end
    type Cat() = inherit Animal()
    
    let cat = Cat()
    cat |> is //true
    

提交回复
热议问题