Last active
April 27, 2022 16:22
-
-
Save ForNeVeR/27d196bc448f1357d8764a22c8488d9b to your computer and use it in GitHub Desktop.
Mystical delegate converter in F#
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
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