Is there some way to convert between F# List and F# Tuple?
For example:
[1;2;3] -> (1,2,3) (1,2,3,4) -> [1;2;3;4]
I need two Functions to do that:
let listToTuple list = ... let tupleToList tuple = ...
Thank you in advance.
If you want to convert Fahrenheit to Celsius, do the opposite: subtract 30 from the temperature in degrees Fahrenheit, and then divide by 2 to get the temperature in degrees Celsius. = 27 °C (In reality, 84 °F is equivalent to 28.89 °C—again, that's a pretty close estimate!).
Besides listToTuple then pblasucci has the right answer. But you wont be happy with the result unless you know something about type types involved, or if you wan't to do a lot of boxing and unboxing.
let tupleToList t = if Microsoft.FSharp.Reflection.FSharpType.IsTuple(t.GetType()) then Some (Microsoft.FSharp.Reflection.FSharpValue.GetTupleFields t |> Array.toList) else None 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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With