Created
January 29, 2012 11:08
-
-
Save bleis-tift/1698305 to your computer and use it in GitHub Desktop.
obj list型のxsをtのlistにするコード(tはSystem.Typeオブジェクト)
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 Microsoft.FSharp.Reflection | |
let listType = typedefof<list<_>>.MakeGenericType([| t |]) | |
let cases = FSharpType.GetUnionCases(listType) | |
let nil, cons = cases.[0], cases.[1] | |
let lst = FSharpValue.MakeUnion(nil, [||]) | |
let consR x xs = | |
ref (FSharpValue.MakeUnion(cons, [| x; !xs |])) | |
!(List.foldBack consR xs (ref lst)) |> unbox |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment