Created
September 9, 2010 13:35
-
-
Save t0yv0/571858 to your computer and use it in GitHub Desktop.
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 Specialization = | |
type ITyped<'T1,'T2> = | |
abstract member Run<'T3> : 'T1 -> 'T2 | |
type private Function<'T1,'T2> = delegate of 'T1 -> 'T2 | |
let Specialize<'T1,'T2> (algorithm: ITyped<'T1,'T2>) = | |
let aT = typeof<ITyped<'T1,'T2>> | |
let def = aT.GetMethod("Run").GetGenericMethodDefinition() | |
let dT = typeof<Function<'T1,'T2>> | |
fun (t: System.Type) -> | |
let m = def.MakeGenericMethod [| t |] | |
let f = System.Delegate.CreateDelegate(dT, algorithm, m) | |
(f :?> Function<'T1,'T2>).Invoke | |
(* | |
Specialization.Specialize | |
{ new Specialization.ITyped<unit,string> with | |
member this.Run<'T>(_) = | |
typeof<'T>.Name | |
} | |
typeof<string> | |
() | |
*) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment