Skip to content

Instantly share code, notes, and snippets.

@bleis-tift
Created January 29, 2012 11:08
Show Gist options
  • Save bleis-tift/1698305 to your computer and use it in GitHub Desktop.
Save bleis-tift/1698305 to your computer and use it in GitHub Desktop.
obj list型のxsをtのlistにするコード(tはSystem.Typeオブジェクト)
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