List to Tuple

Category:
Lists, Tuples and Options
Description: This sample convert a list to a tuple
Code:
let ListToTuple() = 
let listToTuple l =
let l' = List.toArray l
let types = l' |> Array.map (fun o -> o.GetType())
let tupleType = Microsoft.FSharp.Reflection.FSharpType.MakeTupleType types
Microsoft.FSharp.Reflection.FSharpValue.MakeTuple (l' , tupleType)
let r = (listToTuple [1,2,3,4]) |> Microsoft.FSharp.Reflection.FSharpValue.GetTupleFields
r.[0] |> printfn "%A"


Execution Result:
(1, 2, 3, 4)

Last edited Sep 14, 2011 at 2:48 AM by ttliu2000, version 1

Comments

No comments yet.