所以我刚刚开始使用F#,我遇到了一个非常奇怪的问题,当我使用FSharp PowerPack中的某些方法时会抛出System.MissingMethodException.
对于同一模块中的所有方法都不会发生这种情况.如果我将程序集编译为Application而不是类库,也不会发生这种情况.
复制步骤:
在每个装配中创建以下测试夹具.
open NUnit.Framework
[<TestFixture>]
type Tests() = class
[<Test>]
member self.OfSeq() =
// Will always succeed
Matrix.Generic.ofSeq [[1]] |> ignore
[<Test>]
member self.OfList() =
// Will fail under certain conditions with a System.MissingMethodException
Matrix.Generic.ofList [[1]] |> ignore
end
Run Code Online (Sandbox Code Playgroud)当我这样做时,应用程序运行正常(所有测试都通过),但类库失败,出现以下异常:
System.MissingMethodException : Method not found: 'Microsoft.FSharp.Math.Matrix`1<!!0> Generic.ofList(Microsoft.FSharp.Collections.FSharpList`1<Microsoft.FSharp.Collections.FSharpList`1<!!0>>)'.
at Temp2.Tests.OfList()
Run Code Online (Sandbox Code Playgroud)
这里发生了什么?
产生问题的另一种方法是matrix.PermuteColumns.
附加信息:
如果有其他信息可以使用,请告诉我.
给出一个简单的元组序列,以及使用F#PowerPack的PSeq的并行序列:
let a = Seq.singleton (1,"a") --> val a: seq<int * string>
let b = a |> PSeq.map id --> val b: pseq<int * string>
Run Code Online (Sandbox Code Playgroud)
现在我想从他们创建一个.Net BCL字典:
let bd = b.ToDictionary(fst, snd, HashIdentity.Structural)
let ad = a.ToDictionary(fst, snd, HashIdentity.Structural)
let ad2 = a.ToDictionary(fst, snd)
let ad3 = a.ToDictionary((fun (x,y) -> x), (fun (x,y) -> y), HashIdentity.Structural)
Run Code Online (Sandbox Code Playgroud)
虽然let bd
有效let ad
但无法编译,因为它无法推断类型并正确转换为BCL的Func.有趣的是,如果我省略第三个参数let ad2
,或者如果我写出来fst
并snd
手动内联,它就可以正常工作let ad3
.
该表达式应该具有类型Func <(int*string),'a>但这里有类型'b*'c - >'b
let ad …
我在Win 8 Consumer Preview上使用VS11 Beta.安装VS11 Beta后我安装了F#3.0 SDK.但我无法找到兼容的,FSharp.PowerPack.dll
因为CodePlex仅提供PowerPack for F#2.0.
知道怎么处理这个吗?
我一直在阅读F#核心库源代码(v.2.0)并发现了一些相当有趣的东西:
List.foldBack
通过一个可变数组实现,不像那样List.fold
非常简单.这是源代码,或者您可以在此处找到它:
let foldArraySubRight (f:OptimizedClosures.FSharpFunc<'T,_,_>) (arr: 'T[]) start fin acc =
let mutable state = acc
for i = fin downto start do
state <- f.Invoke(arr.[i], state)
state
// this version doesn't causes stack overflow - it uses a private stack
let foldBack<'T,'State> f (list:'T list) (acc:'State) =
// skipped optimized implementations for known lists
// It is faster to allocate and iterate an array than to create all those
// highly nested …
Run Code Online (Sandbox Code Playgroud)