I am using Microsoft.FSharp.Reflection.FSharpValue.MakeUnion and this requires a Reflection.UnionCaseInfo and an obj[] (that can be empty) as parameters.
However, I am getting a Type mismatch. Expecting a obj [] but given a string [] The type 'obj' does not match the type 'string' when calling with the result of a function that is a string[].
The simplest example I can create of this happening is as follows (I have a test wrapped around this and it doesn't compile because of the line marked !!.
let one (a:obj[]) = a |> Array.map (fun o->printfn "%A" o) |> ignore one [|"a";"b";"c"|] // OK! let str = [|"a";"b";"c"|] //the equivalent of my function return one str//!!Type mismatch. I am not sure if I am meant to be casting/converting string[] into an obj[] or ... well, if I am just doing something else wrong that I don't know about.
edit: the actual issue is as described below
let split (by:string) (input:string) = System.Text.RegularExpressions.Regex.Split(input,by) let buildArgs content = match content with | "" -> [||] | _ -> content |> split " " //Type mismatch this is what I used to solve: is there a better way?
| _ -> content |> split " "|> Array.map (fun s->s:>obj)//make sure obj[] is returned Casting and Conversions (F#) as reference
I have also tried this
let buildArgs content :obj[] = ... // Type mismatch but that also gives me an error:
Type Mismatch on the last line of the function if I don't do the
Array.map.
FSharpValue.MakeUnion(unless I am mistaken)(fun s -> s:>obj)toboxbuildArgsas defined does not give me any type mismatch - it returns a string arraybuildArgsis(content |> split " ") |> box |> unbox