How to downcast from obj to option?

前端 未结 3 1974
粉色の甜心
粉色の甜心 2021-01-11 12:49

I have a function that takes a parameter of type object and needs to downcast it to an option.

member s.Bind(x : obj, rest) =
    let         


        
3条回答
  •  春和景丽
    2021-01-11 13:50

    I am not certain why you need to get your input as obj, but if your input is an Option<_>, then it is easy:

    member t.Bind (x : 'a option, rest : obj option -> 'b) =
        let x = // val x : obj option
            x
            |> Option.bind (box >> Some)
        rest x
    

提交回复
热议问题