The class System.Collections.Immutable.ImmutableHashSet<'t> has a nested type Builder. We can use it in F# without issues.
What I would like to do is add an extension method to that class in F#, like
type ImmutableHashSet<'t>.Builder with
member this.NewMember() = ...
but this is not valid F# syntax.
If I extract the fsi I see the following definition
namespace System.Collections.Immutable.ImmutableHashSet`1
type Builder<'T> = ...
however the syntax
type ``System.Collections.Immutable.ImmutableHashSet`1``.Builder with
member this.NewMember() = ...
is also non valid.
Is there a way to write this extension in F#?
Back-ticks are confusing the markdown, so to clarify what @JL0PD wrote, the following seems to work:
open System.Collections.Immutable
type ``ImmutableHashSet`1``.Builder<'a> with
member _.NewMember() = printfn "Hello world"
let builder = ImmutableHashSet.CreateBuilder<int>()
builder.NewMember() // Hello world
Exposing the mangled name like this is surprising to me, so it's possible that this only works by accident and could change in the future.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With