Search code examples
f#new-operator

Create new operator in F# with explicit datatype


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://learn.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


Solution

  • 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