Warm tip: This article is reproduced from serverfault.com, please click

Create new operator in F# with explicit datatype

发布于 2020-12-02 11:08:40

Is there a way I can explicitly the elements of a new operator I define?

I've checked the doc but couldn't find it: https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/operator-overloading#creating-new-operators

Let's say I have defined the following xor operator:

let (^@) a b =
    a <> b

let result = true ^@ false

It works correctly, but the following definition no...

let (@^) (a: bool, b:bool) : bool =
    a <> b

enter image description here

Questioner
blfuentes
Viewed
0
CaringDev 2020-12-02 19:41:47

In @^ the parameters are tupled. Your operator needs two parameters. If you specify

let (@^) (a: bool) (b: bool) : bool =
    a <> b

then

true @^ false // true