This code runs fine except if I uncomment the last line in my custom seq expression :
type T (i: int) =
member x.i = i
override x.ToString() =
sprintf "T is %A " x.i
type TBuilder() =
member x.Yield (()) = Seq.empty
[<CustomOperation("test")>]
member x.Test1 (source : seq<_>, i: int) : seq<T> =
printfn "Calling Test1 with i= %d" i |> ignore
seq { yield! source
yield T(i) }
let t = TBuilder()
let mytest =
t {
test 42
test 43
// yield T(44) // if uncommented, it does not compile
}
If yield T(44) line is uncommented, I get an compiler error like so :
Error This control construct may only be used if the computation expression builder defines a 'For' method.
My question : Is there a way to mix
- my [CustomOperation] test (from method Test1) that yields T objects
with
- a vanilla yield, for example
yield T(44)or any other seq related syntax
inside a unique seq expression BUT without defining any 'For' method ?
Reference : DSL in Action for F# (Chapter 7) by Anh-Dung Phan on github. Thanks.