Skip to content

Instantly share code, notes, and snippets.

@ashmind
Created August 2, 2012 02:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashmind/3232454 to your computer and use it in GitHub Desktop.
Save ashmind/3232454 to your computer and use it in GitHub Desktop.
F# first class generic function cheating
open System
type Test() =
let f = fun x -> x
member this.F with get() = f
let t = Test()
ignore (t.F "5") // 1
// ignore (t.F 5) // 2
Console.WriteLine(t.F.GetType().BaseType)
// writes:
// 1: Microsoft.FSharp.Core.FSharpFunc`2[System.String,System.String]
// 2: Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,System.Int32]
// 1 and 2: error FS0001: This expression was expected to have type string but here has type int
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment