Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // get the Map module
- let map = mapType.Assembly.GetTypes() |> Array.find(fun t -> t.Name = "MapModule")
- // get the MapModule.iter function
- let iter = map.GetMethods(BindingFlags.Static ||| BindingFlags.Public) |> Array.find (fun m -> m.Name = "Iterate")
- // create a unction that we want to pass to Map.iter
- let iterator = (fun k v -> printfn k)
- // get type of iterator function
- let fType = iterator.GetType()
- // tried to build a function type
- let f1Type = FSharpType.MakeFunctionType ( fType, FSharpType.MakeFunctionType(ttt4.GetType(), typeof<unit> ) )
- // specialise the generic function
- let genericIter = iter.MakeGenericMethod([| fType ; ttt4.GetType() |])
- //invoke the Map.iter function with our iterator function, and the map instance ttt4
- genericIter.Invoke(null, [| iterator; ttt4 |]) |> ignore
- (*
- Unhandled Exception: System.ArgumentException: Object of type 'Program+iterator@288TT[System.Object,System.Object]' cannot be converted to type
- 'FSharpFunc`2[
- Program+iterator@288TT[System.Object,System.Object],
- FSharpFunc`2[
- FSharpMap`2[
- System.String,
- User+User
- ],
- Unit
- ]
- ]'.
- at System.RuntimeType.TryChangeType(Object value, Binder binder, CultureInfo culture, Boolean needsSpecialCast)
- at System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig)
- at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
- at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
- *)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement