Extending F# List Module

♀尐吖头ヾ 提交于 2019-12-05 05:42:29

Generic extension methods are now available in F# 3.1:

open System.Runtime.CompilerServices

[<Extension>]
type Utils () =
    [<Extension>]
    static member inline AppendMutate(ref: Ref<List<'a>>, elt) = ref := elt :: !ref

let ls = ref [1..10]

ls.AppendMutate(11)

printfn "%A" ls

Unfortunately, it doesn't appear to be possible to add extension members to closed constructed types (e.g. Ref<int> or Seq<string>). This also applies to the code you're trying to use, since you're substituting the more specific type 'a list for the generic parameter 'T of the open generic Ref<'T> type.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!