How to define explicit operator in F#?
문제
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)
제휴하지 않습니다 StackOverflow