我想在我的计算表达式上定义一些自定义运算符,但无法使其工作
type ZipSeq() =
[<CustomOperation("<*>")>]
member this.Apply f s =
f |> Seq.zip s |> Seq.map (fun (y, x) -> x(y))
member this.Return x =
Seq.initInfinite (fun _ -> x)
// (a -> b) -> seq<a> -> seq<b>
[<CustomOperation("<!>")>]
member this.Map f s =
this.Apply (this.Return f) s
let zipSeq = new ZipSeq()
let f (a : float) = a * a
let s = seq { yield 1. }
// seq<b>
let h1 = zipSeq.Map f s
//thinking h1 should be the same as h2
//but compilation error : ` This value is not a function and cannot be applied`
let h2 = zipSeq { return f <!> s }
顺便说一句,更改member this.Map f s ...
为member this.Map (f, s) ...
给出相同的错误。