I am trying to create a function in F # that converts some types to string, but not others. The goal is so that the primitive can be transmitted, but a complex object cannot be transferred by accident. Here is what I still have:
type Conversions =
static member Convert (value:int) =
value.ToString()
static member Convert (value:bool) =
value.ToString()
let inline convHelper< ^t, ^v when ^t : (static member Convert : ^v -> string) > (value:^v) =
( ^t : (static member Convert : ^v -> string) (value))
let inline conv (value:^v) = convHelper<Conversions, ^v>(value)
Unfortunately, my function convgets the following compile time error:
A unique overload for method 'Convert' could not be determined based on type information
prior to this program point. A type annotation may be needed. Candidates:
static member Conversions.Convert : value:bool -> string,
static member Conversions.Convert : value:int -> string
What am I doing wrong?
source
share