Here is someway to support method overloading with F# and to create a bind function.
first create an inline operator
let inline (>>=) (f: ^U -> ^T) (t:^T) =
let bind' = (^T : (member bind : (^U -> ^T) -> ^T) (t, f))
bind'
then implement member functions for bind
on those types that should support bind
type Baz = Baz of int with
member this.bind (f: 'a -> 'b): 'b = match this with | Baz i -> f i
type Foo = Foo of string with
member this.bind (f: 'a -> 'b): 'b = match this with | Foo i -> f i
finally call the the bind
let x = (fun x -> (Baz(x+1))) >>= (Baz 1)
let y = (fun x -> (Foo(x+"!"))) >>= (Foo "yeah")
And the below fails with an compile error
type FooBar = FooBar of string
let y = (fun x -> (FooBar(x+"!"))) >>= (FooBar "yeah")