i want to extend the option type with a join method and a contrained function.
type Option<'a> with
member this.join r =
match r with
| Some s ->
match s with
| Some really as r -> r
| _ -> None
| _ -> None
Calling the method works fine as expected.
let x = None.join(Some (Some 1))
Now I want to define an overloaded function (inline and constraints as this is the only way in F#)
let inline join (t:^T) : ^U = (^T : (member join : ^T -> ^U) (t,t))
and call it like this
join (Some (Some 1))
However now I get the error message
The type ''a option' does not support the operator 'join'
union case Option.Some: Value: 'T -> Option<'T>
The representation of "Value of type 'T"
which is strange insofar as I can write another type like this
type Result<'TSuccess, 'TError> =
| Success of 'TSuccess
| Error of 'TError list
member this.join r =
match r with
| Success(s) ->
match s with
| Success(really) -> Success(really)
| Error(e) -> Error(e)
| Error(e) -> Error e
and use it like this
join (Success (Success 1))
the difference being that in this case there is no extension method.
Any ideas anybody?