에서 사용자 정의 연산자를 정의하지만 member this.Map (f, s) ...
에 member this.Map f s ...
을 변경 Btw는계산 표현
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 }
를 작동 할 수 없습니다 어떻게 같은 오류를 제공합니다.
나는 그것이 가능하지 않다고 생각합니다. 그래도 멋지다. – Tarmil
당신은 계산 빌더의 일부가 아닌이 연산자들을 따로 따로 정의하여이 문법을 구현할 수 있어야하고, 그것들은'let!'-ed 또는'return! '일 수있는 모나드 인스턴스를 반환하게한다 - 에드. –
다른 대안을 제안 해 주시겠습니까? – baio