标签: f#-powerpack

使用FSharp PowerPack中的某些方法并编译为类库时System.MissingMethodException

所以我刚刚开始使用F#,我遇到了一个非常奇怪的问题,当我使用FSharp PowerPack中的某些方法时会抛出System.MissingMethodException.

对于同一模块中的所有方法都不会发生这种情况.如果我将程序集编译为Application而不是类库,也不会发生这种情况.

复制步骤:

  1. 创建2个程序集,一个类库和一个应用程序.
  2. 添加nunit.framework和FSharp.PowerPack DLL作为对两个程序集的引用.
  3. 在每个装配中创建以下测试夹具.

    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)
  4. 编译两个程序集.
  5. 在NUnit中打开每个程序集并运行所有测试.

当我这样做时,应用程序运行正常(所有测试都通过),但类库失败,出现以下异常:

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.

附加信息:

  • 我正在为.NET 4.5编译两个程序集
  • 我正在使用Visual Studio 2012 RC进行编译
  • 我正在使用NUnit版本2.5.10.11092
  • 我正在使用FSharp PowerPack版本2.1.3.1(虽然DLL属性声明它是2.0.0)

如果有其他信息可以使用,请告诉我.

f# missingmethodexception f#-powerpack

8
推荐指数
2
解决办法
1935
查看次数

F#Func类型推断Seq和PSeq ToDictionary之间的区别

给出一个简单的元组序列,以及使用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,或者如果我写出来fstsnd手动内联,它就可以正常工作let ad3.

该表达式应该具有类型Func <(int*string),'a>但这里有类型'b*'c - >'b

  • 为什么不let ad …

f# f#-3.0 f#-powerpack

7
推荐指数
1
解决办法
470
查看次数

如何获得F#3.0的F#powerpack

我在Win 8 Consumer Preview上使用VS11 Beta.安装VS11 Beta后我安装了F#3.0 SDK.但我无法找到兼容的,FSharp.PowerPack.dll因为CodePlex仅提供PowerPack for F#2.0.

知道怎么处理这个吗?

f# windows-8 f#-3.0 f#-powerpack

6
推荐指数
2
解决办法
2004
查看次数

为什么List.foldBack是通过可变数组实现的(而不是通过延续)?

我一直在阅读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)

f# f#-powerpack

5
推荐指数
2
解决办法
911
查看次数