Skip to content

Instantly share code, notes, and snippets.

@MelbourneDeveloper
Created September 25, 2023 21:00
Show Gist options
  • Save MelbourneDeveloper/67e36f2088693cd8d50a62d2f1b02936 to your computer and use it in GitHub Desktop.
Save MelbourneDeveloper/67e36f2088693cd8d50a62d2f1b02936 to your computer and use it in GitHub Desktop.
F# Type Inference By Interpolation Not Working
module Thing
type Factory<'T> = unit -> 'T
type Printer () =
static member FactoryInstance : Factory<'T> = Printer.FactoryFunction
static member DoPrinting () =
let factory = Printer.FactoryInstance
printfn $"Values %s{Printer.FactoryInstance ()} and %d{Printer.FactoryInstance ()}"
()
static member FactoryFunction<'T> () : 'T =
if typeof<'T> = typeof<string> then
box "String" :?> 'T
elif typeof<'T> = typeof<int> then
box 1 :?> 'T
else
failwith "Type is not supported"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment