[英]F# Cast as Prefix Operator
In F#, many infix operators can be made prefix operators: 在F#中,许多中缀运算符可以成为前缀运算符:
a + b
(+) 1 a b
However, this doesn't seem to be allowed for the upcast (or downcast) operators. 但是,对于向上(或向下)运营商来说,似乎不允许这样做。
x
is a UserPrincipal
, which inherits from Principal
x
是UserPrincipal
,它继承自Principal
x :> Principal
(:>) x Principal
Why? 为什么?
Probably because unlike other operators, the cast operators don't take two expressions as arguments; 可能因为与其他运算符不同,转换运算符不会将两个表达式作为参数; they take an expression and a type.
他们采取表达和类型。 So
(:>) x
would have to be "a function that takes a type", which is not a thing that exists in F#. 所以
(:>) x
必须是“一个带有类型的函数”,这不是F#中存在的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.