Created
September 25, 2023 21:00
-
-
Save MelbourneDeveloper/67e36f2088693cd8d50a62d2f1b02936 to your computer and use it in GitHub Desktop.
F# Type Inference By Interpolation Not Working
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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