문제

How do you implement the equivalent of C#'s explicit operator in F#? Is it supported?

도움이 되었습니까?

해결책

Just implement an op_Explicit static member like

type SomeType() =
    static member op_Explicit(source: SomeType) : int =
        1

and then you can use a corresponding F# explicit conversion operator like

SomeType() |> int

you can see a bit into how this works by noting the static member constraint on the type signature of int

^a -> int when  ^a : (static member op_Explicit :  ^a -> int)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top