Why can't I use pattern matching function
in computation expressions without implement Zero
member?
For example, could somepone explain why it permits allowing pattern matching expression
but not pattern matching function
?
type MaybeBuilder() =
member __.Bind (x, f) = match x with Some a -> f a | None -> None
member __.Return x = Some x
let maybe = MaybeBuilder()
// Errors: FS0708 This control construct may only be used
// if the computation expression builder defines a 'Zero' method
maybe { Some 1 |> function Some x -> return x | None -> return 0 }
maybe { Some 1 |> fun x -> match x with Some x' -> return x' | None -> return 0 }
// Ok
maybe { match Some 1 with Some x -> return x | None -> return 0 }