Reading through the F# 4.0 spec, I saw the following on page 79 of the PDF:
The auxiliary function
src(e)denotesb.Source(e)if the innermost ForEach is from the user code instead of generated by the translation, and a builderbcontains aSourcemethod. Otherwise,src(e)denotese.
This is in the context of the spec's detailed (VERY detailed) description of how computation expressions are parsed and turned into a series of method calls on the expression's builder object. Scott Wlaschin's Computation Expressions series, which I found to be invaluable in helping me understand the rest of the concepts behind computation expressions, doesn't mention a Source method, nor does any other reference I've been able to find. (Google isn't much help with this one, as tons of people talk about source code and any references to Source methods gets buried).
I also don't see Source documented anywhere in the MSDN page on computation expressions. The QueryBuilder class uses Source, so I have one example I can look at, but there's no explanation of why this would be useful in other circumstances.
Under what circumstances would you want to have a Source method on a custom computation expression builder? What would be a scenario where the default ForEach handling is inadequate to one's needs and a Source method would be useful?
Source()is being called with the contents of theinclause (i.e.,for item in xproduces a call toSource(x)). And I understand thatSourceshould return something suitable to pass into theFor. I don't quite see why, though.QueryBuilder.Sourcewants either an IEnumerable or an IQueryable (which inherits from IEnumerable), both of which are suitable for aForfunction to iterate over. So why is theSourcecall needed here? Why not just say "They gave me an IEnumerable, so I'll iterate over it"? - rmunnForI'm talking about isQueryBuilder.For, which is called to handle theforexpression inquery { **for** customer in db.Customers do select customer }. - rmunn