this post
,F#支持对象实例和静态类上的扩展方法。例如:
module CollectionExtensions =
type System.Linq.Enumerable with
static member RangeChar(first:char, last:char) = {first .. last}
open ExtensionFSharp.CollectionExtensions
System.Linq.Enumerable.
静态法
RangeChar
出现在我的智能感知窗口中。
我想添加一个静态方法,
for_alli
module SeqExtensions =
type Microsoft.FSharp.Collections.Seq with (* error on this line *)
static member for_alli f l =
l
|> Seq.mapi (fun i x -> i, x)
|> Seq.for_all (fun (i, x) -> f i x)
虽然两段代码的结构相同,
SeqExtensions
不编译。F#突出显示单词
Seq
如何在Seq模块上创建静态扩展方法?