Last active
December 20, 2015 04:19
-
-
Save wattsm/6070195 to your computer and use it in GitHub Desktop.
Creating an F# list via reflection
This file contains hidden or 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
let makeListOf itemType (items : obj list) = | |
let listType = | |
makeGenericType | |
<| typedefof<Microsoft.FSharp.Collections.List<_>> | |
<| [ itemType; ] | |
let add = | |
let cons = | |
listType.GetMethod ("Cons") | |
fun item list -> | |
cons.Invoke (null, [| item; list; |]) | |
let list = | |
let empty = | |
listType.GetProperty ("Empty") | |
empty.GetValue (null) | |
list | |
|> List.foldBack add items |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment