Why does this F # evaluation expression give a warning?

This code:

type Result = Success of string

type Tracer() =
  member x.Bind(p: Result, rest: (string -> Result)) = 
    match p with
    | Success s -> rest s

let tracer = new Tracer()

let t = tracer {
  let! x = Success "yes!"
  let! y = Success "waste of time"
  return! Success x
}

printfn "%A" t

prints success "yes!"

But gives a warning, which implies that it should not work:

File1.fs (19.3): warning FS0708: this control construct can only be used if the expression builder defines the "ReturnFrom" method

It seems like a strange warning: if this is correct, then the code should not work. Does it just say that the builder had to synthesize ReturnFrom?

(F # version 1.9.7.4, compilation for .NET Framework version 4.0.21006)

+3
source share
2 answers

fsbugs@microsoft.com, . , .

( , - , .)

+6

, . 6.10 ReturnFrom, . member x.ReturnFrom v = v ? a member x.Return(v) = Success v, tracer return x, ?

+4

Source: https://habr.com/ru/post/1723945/


All Articles