Skip to content

Instantly share code, notes, and snippets.

@ForNeVeR
Last active April 27, 2022 16:22
Show Gist options
  • Save ForNeVeR/27d196bc448f1357d8764a22c8488d9b to your computer and use it in GitHub Desktop.
Save ForNeVeR/27d196bc448f1357d8764a22c8488d9b to your computer and use it in GitHub Desktop.
Mystical delegate converter in F#
open System
type Del = delegate of int -> int
let convert1 (d: Func<int, int>): Del = (# "" d : Del #)
let convert2 (d: Func<int, int>): Del = Del(fun x -> d.Invoke x)
[<EntryPoint>]
let main argv =
let x = Func<int, int>(fun x -> x)
let y = convert1 x
let z = convert2 x
printfn "%A" (x.GetType()) // System.Func`2[System.Int32,System.Int32]
printfn "%A" (y.GetType()) // System.Func`2[System.Int32,System.Int32]
printfn "%A" (z.GetType()) // Program+Del
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment