给出以下代码
type Init<'a> = Init of 'a
type Right<'a> = Right of 'a
type Left<'a> = Left of 'a
type MovesBuilder(init) =
member x.Yield(()) = Init init
[<CustomOperation("left")>]
member x.Left(Init v) = Left "Left"
[<CustomOperation("right")>]
member x.Right(Left v) = Right "Right"
let moves v = MovesBuilder(v)
我想这样做
let test1 =
moves 1 { left
right }
但我收到此错误消息
moves 1 { left
----------^^^^
stdin(565,13): error FS3099: 'left' is used with an incorrect number of
arguments. This is a custom operation in this query or computation
expression. Expected 0 argument(s), but given 1.
我也试过这个
let test2 =
moves(1) { left
right }
let test3 =
(moves 1) { left
right }
type MovesFactory(init) =
member self.create = MovesBuilder(init)
let test4 =
MovesFactory(3).create { left
right }
可悲的是,所有人都给我一个错误。