Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net F#,Deedle:约束到类型Frame的泛型Frame<;obj,obj>;_.net_Functional Programming_F#_Deedle - Fatal编程技术网

.net F#,Deedle:约束到类型Frame的泛型Frame<;obj,obj>;

.net F#,Deedle:约束到类型Frame的泛型Frame<;obj,obj>;,.net,functional-programming,f#,deedle,.net,Functional Programming,F#,Deedle,我有一个函数,它接收一个obj并尝试猜测它是字符串、Deedle帧还是其他内容: let exampleF (data : obj) = match data with | :? string as s -> "string: " + s | :? Frame<'a,'b> as d -> "Frame" | _ -> "something else" 举个例子(数据:obj)= 将数据与 | :? 字符串形式为s->“字符串:”+

我有一个函数,它接收一个obj并尝试猜测它是字符串、Deedle帧还是其他内容:

let exampleF (data : obj) =
    match data with
    | :? string as s -> "string: " + s
    | :? Frame<'a,'b> as d -> "Frame"
    | _ -> "something else"
举个例子(数据:obj)=
将数据与
| :? 字符串形式为s->“字符串:”+s
| :? 帧为d->“帧”
|——>“还有别的”
问题是帧被约束为类型Frame。所以,如果我有Frame类型的框架,exampleF将输出“somethinother”。然而,如果exampleF有另一个分支,其中“?Frame为d->”,那么someFrame将被正确捕获


我怎样才能在这样的模式匹配中捕获所有帧,而不必指定内部类型?

Jim Foye帮助我找到了答案:

let exampleF data =
    match data.GetType() with
    | typ when typ.IsGenericType && typ.GetGenericTypeDefinition() = typedefof<Frame<_,_>> -> "Frame"
    | typ when typ = typeof<string> -> "string"
    | _ -> "something else"
让我们以数据为例=
将data.GetType()与
|typ.IsGenericType&&typ.GetGenericTypeDefinition()=typedefof->“Frame”时的类型
|当typ=typeof->“字符串”时的typ
|——>“还有别的”

关于这一点已有一些讨论,例如,吉姆,非常感谢。我在提问前搜索了一下,但似乎我没有幸运地选择正确的搜索词。