小编Cod*_*ard的帖子

obj []和string []作为参数

我正在使用Microsoft.FSharp.Reflection.FSharpValue.MakeUnion,这需要一个Reflection.UnionCaseInfo和一个obj[](可以是空的)作为参数.

但是,我正在 Type mismatch. Expecting a obj [] but given a string [] The type 'obj' does not match the type 'string'使用函数的结果调用string[].

我可以创建这个事件的最简单的例子如下(我有一个测试包围这个,它不会编译因为标记的行!!.

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.
Run Code Online (Sandbox Code Playgroud)

我不确定我是不是要将字符串[]转换/转换为obj []或者......好吧,如果我正在做其他错误的事我不知道.

编辑:实际问题如下所述

let split (by:string) (input:string) = System.Text.RegularExpressions.Regex.Split(input,by)

let buildArgs content = 
 match content with …
Run Code Online (Sandbox Code Playgroud)

f# types casting type-conversion

6
推荐指数
1
解决办法
965
查看次数

标签 统计

casting ×1

f# ×1

type-conversion ×1

types ×1