<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Type inference woes, part two</title><link>http://blogs.msdn.com/b/ericlippert/archive/2006/05/26/type-inference-woes-part-two.aspx</link><description>So what's the big deal anyway? The difference between the spec and the implementation is subtle, only affects a few specific and rather unlikely scenarios, and can always be worked around by inserting casts if you need to. Fixing the implementation would</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Type inference woes, part two</title><link>http://blogs.msdn.com/b/ericlippert/archive/2006/05/26/type-inference-woes-part-two.aspx#609240</link><pubDate>Sun, 28 May 2006 13:57:36 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:609240</guid><dc:creator>Peter Ritchie</dc:creator><description>I'd agree with James on the first point. &amp;nbsp;Since &amp;quot;var&amp;quot; doesn't imply type, variable initializer lists shouldn't restrict type and should be considered short-hand for &amp;quot;var x = &amp;lt;value&amp;gt;; var y = &amp;lt;anothervalue&amp;gt;; ...&amp;quot;&lt;br&gt;&lt;br&gt;For point two, I would expect it to be consistent with the way the language currently handles literals and type coercion; if the literal fits within the type of the variable it is assigned to, then just cast it down, i.e.: Int16 x = 0; &amp;nbsp;Zero will obviously fit within Int16 despite technically being Int32. Since var has no type it must be implied through its initialization, with arrays I would expect it to be consistent with the comma operator's associativity rules: evaluating from left to right. &amp;nbsp;In your example, I would expect x to be an array of ints without error because a short value will not overflow (where &amp;quot;Int64 g = 0;var x = new[] {0, g}&amp;quot; would produce an error because x would be inferred to be int[] and g could overflow).&lt;br&gt;&lt;br&gt;Point 3 is a little trickier because there really are no associativity rules to use as a baseline, other than from top to bottom. &amp;nbsp;So, me personally, I would expect top-down evaluation. &amp;nbsp;Since the first return is a zero literal, and is an int, the result should be implicitly considered IEnumerable&amp;lt;int&amp;gt;.&lt;br&gt;&lt;br&gt;Point 4: does lambda always compile into IL, like Generics; or, is it more like C++ templates?&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=609240" width="1" height="1"&gt;</description></item><item><title>re: Type inference woes, part two</title><link>http://blogs.msdn.com/b/ericlippert/archive/2006/05/26/type-inference-woes-part-two.aspx#608292</link><pubDate>Fri, 26 May 2006 22:56:25 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:608292</guid><dc:creator>James S.</dc:creator><description>With regards to the &amp;quot;var x = 0, y = (short) 123;&amp;quot; example, it's interesting that you don't mention even considering making them different types.&lt;br&gt;&lt;br&gt;C++0x has considered the same problem, as part of its &amp;quot;auto x = incarnate_verbosity;&amp;quot; syntax. The proposed wording at the linked URL explains that each initialiser should be deduced to the same type or the program is ill formed. Of course, C++, being far less brash than C#, decided to stop considering the array case in recent drafts :)&lt;br&gt;&lt;br&gt;As for the lambda examples, the question of how the argument type is unified seems like the bigger issue to an outsider... 'c' appears to have latent typing in the example above (the first example, anyway; the second is illegible), making the return type fairly moot (what if the lambda returns a projection of c.Foo?). You haven't mentioned that, so apparently something else is happening: Do you deduce the type of S before knowing what Func&amp;lt;S, T&amp;gt; is and then use that to guide the lambda? Really? How many of them can you chain together? :)&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=608292" width="1" height="1"&gt;</description></item></channel></rss>