如何在F#交互中使用Span?

时间:2018-10-30 17:47:15

标签: f# .net-core f#-interactive f#-scripting

我尝试添加对System.Memory的引用,

#r "C:/Program Files/dotnet/shared/Microsoft.NETCore.App/2.1.5/System.Memory.dll"

但是F#交互式仍然说The value or constructor 'Span' is not defined。当我尝试使用打开的System.Memory时,它会显示The namespace 'Memory' is not defined。有办法吗?

1 个答案:

答案 0 :(得分:3)

您不需要open System.Memory,但您需要open System。您可能还希望先将System.Memory放入.NET Framework应用程序中,然后再引用它。我不知道FSI将如何与Span<T>进行交互。

#if INTERACTIVE
#r @"C:\Users\username\Documents\Source\ConsoleApplication1\packages\System.Memory.4.5.1\lib\netstandard2.0\System.Memory.dll"
#r "System.Runtime.dll"
#endif


open System
open System.Runtime.CompilerServices

[<IsByRefLike; Struct>]
type S(count1: Span<int>, count2: Span<int>) =
    member x.Count1 = count1
    member x.Count2 = count2