Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何explicit在 F# 中实现相当于 C# 的运算符?是否支持?
explicit
只需实现一个op_Explicit静态成员,如
op_Explicit
type SomeType() = static member op_Explicit(source: SomeType) : int = 1
然后您可以使用相应的 F# 显式转换运算符,例如
SomeType() |> int
您可以通过注意类型签名上的静态成员约束来了解它是如何工作的int
int
^a -> int when ^a : (static member op_Explicit : ^a -> int)