Looking at the reflected code, the first example creates a sequence, which is then coverted to a list using SeqModule.ToList. The second creates a list directly using Cons.

In other words, the underlying behavior roughly mirrors the language-level expression, albeit with the sequence stuff created and added by the compiler. (The "for" and "..." forms also result in sequences. The former creates a class, while the latter uses a built-in operator.)

So in this case, the second version is more efficient if you really just need a list comprehension based on some known values. If you really needed to (for example) lazy evaluate a sequence, the second form would be required. Another use would be where the sequence-based comprehension is likely more elegant and efficient than a Cons. E.g. [0..1000] vs. listing all 1001 values in the source.

The sample is simple enough that this difference doesn't really stand out.

-Neil

By on 8/3/2010 11:06 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper