How to use Span in F# interactive?

Viewed 626

I try to add reference to System.Memory by

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

But F# interactive still says The value or constructor 'Span' is not defined. And When I try to use open System.Memory it says The namespace 'Memory' is not defined. Is there a way to do this?

1 Answers

You don't need to open System.Memory but you do need to open System. You might also want to nuget System.Memory into a .NET framework application first, and then reference it. I wonder though how FSI will interact with 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  
Related