First of all, F # fully supports method overloading:
type T = static member M (a: int) = a static member M (a: string) = a let x = TM 5 let y = TM "5"
Then you can actually overload the top-level operator with the first argument using statically permitted type constraints and some clever syntax cheating:
type U = U with static member inline ($) (U, a: int) = fun (b: string) -> a + b.Length static member inline ($) (U, a: System.DateTime) = fun (b: int) -> string (int a.Ticks + b) static member inline ($) (U, a: string) = fun (b: int) -> a.Length + b let inline (=>) (a: ^a) (b: ^b) = (U $ a) b let a = 5 => "55" // = 7 let b = System.DateTime.MinValue => 55 // = "55" let c = "55" => 7 // = "9" let d = 5 => "55" => "66" => "77" // = 11
And finally, if you really want to overload the second argument, you can also do this by enlisting the help of the overloaded instance methods:
type I(a: int) = member this.ap(b: string) = a + b.Length member this.ap(b: int) = string( a + b ) type S(a: string) = member this.ap(b: int) = b + a.Length member this.ap(b: string) = b.Length + a.Length type W = W with static member inline ($) (W, a: int) = I a static member inline ($) (W, a: string) = S a let inline ap (a: ^a) (b: ^b) = (^a : (member ap: ^b -> ^c) (a, b)) let inline (==>) (a: ^a) (b: ^b) = ap (W $ a) b let aa = 5 ==> "55"
The disadvantage (or, according to some, up) is that all this happens during compilation (see those inline all over the place?). True class types will definitely be better, but you can do a lot with just static type and overload constraints.
And of course, you can also do good inheritance in F #:
type Base() = class end type A() = inherit Base() type B() = inherit Base() let (===>) (a:
But ... Inheritance? Really?
However, this is rarely worth the trouble. In practice, you can usually achieve your ultimate goal with regular functions and maybe just sprinkle on optionally openable user statements, just for added convenience. Overloaded operators may initially look like a shiny cool toy, but they are dangerously easy to abuse. Remember C ++, learn the lessons :-)