Brett Rowberry
Brett Rowberry

Reputation: 1050

F# Cast as Prefix Operator

In F#, many infix operators can be made prefix operators:

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 :> Principal
(:>) x Principal

Why?

Upvotes: 1

Views: 124

Answers (1)

Tarmil
Tarmil

Reputation: 11362

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#.

Upvotes: 3

Related Questions