<?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>jaredpar's WebLog : F#</title><link>http://blogs.msdn.com/jaredpar/archive/tags/F_2300_/default.aspx</link><description>Tags: F#</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Making F# type inference friendly for C#</title><link>http://blogs.msdn.com/jaredpar/archive/2009/12/15/making-f-type-inference-friendly-for-c.aspx</link><pubDate>Tue, 15 Dec 2009 19:53:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9937228</guid><dc:creator>Jared Parsons</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/jaredpar/comments/9937228.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jaredpar/commentrss.aspx?PostID=9937228</wfw:commentRss><wfw:comment>http://blogs.msdn.com/jaredpar/rsscomments.aspx?PostID=9937228</wfw:comment><description>&lt;p&gt;One of my current hobby projects, &lt;a href="http://blogs.msdn.com/jaredpar/archive/2009/12/14/vsvim-update-released-version-0-5-4.aspx"&gt;VsVim&lt;/a&gt;, requires me to make a lot of calls between F# and C# projects.&amp;#160; The core Vim engine is a pure F# solution based on Visual Studio’s new editor.&amp;#160; It additionally has a small hosting layer and a large test bed both written in C#.&amp;#160; &lt;/p&gt;  &lt;p&gt;When working with the exposed core Vim engine API, I’ve found a number of generated F# constructs which are not easily accessible from C#.&amp;#160; The problem stems from the manner in which native F# types are exposed.&amp;#160; Many of them are generic and&amp;#160; lack type inference friendly helper methods that force awkward usage patterns in C#.&amp;#160; Most painful is the FSharpOption&amp;lt;T&amp;gt; type because it’s a type I frequently expose in APIs.&amp;#160; &lt;/p&gt;  &lt;p&gt;FSharpOption&amp;lt;T&amp;gt; is the exposed type for the native F# &lt;a href="http://msdn.microsoft.com/en-us/library/dd233245(VS.100).aspx"&gt;option&lt;/a&gt; construct representing a value which may or may not be present. It’s similar to C#’s nullable type except that it applies to all types of values.&amp;#160; The primary operations you want to do with an FSharpOption&amp;lt;T&amp;gt; are &lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Create an option with a value &lt;/li&gt;    &lt;li&gt;Create an option without a value &lt;/li&gt;    &lt;li&gt;Determine if it has a value &lt;/li&gt;    &lt;li&gt;Determine if it does not have a value &lt;/li&gt;    &lt;li&gt;Access the value &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;In F# using an option is an inherent part of the language and the hence the resulting code is very elegant. &lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;let &lt;/span&gt;OptionExample = 
    &lt;span style="color: blue"&gt;let &lt;/span&gt;optionWithValue = Some(&lt;span style="color: brown"&gt;42&lt;/span&gt;)
    &lt;span style="color: blue"&gt;let &lt;/span&gt;optionWithoutValue = None
    &lt;span style="color: blue"&gt;let &lt;/span&gt;isSome = Option.isSome optionWithValue
    &lt;span style="color: blue"&gt;let &lt;/span&gt;isNone = Option.isNone optionWithoutValue
    Option.get optionWithValue&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Unfortunately the equivalent C# code is not nearly so nice.&amp;#160; &lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;static int &lt;/span&gt;OptionExample() {
    &lt;span style="color: blue"&gt;var &lt;/span&gt;optionWithValue = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;FSharpOption&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&amp;gt;(&lt;span style="color: brown"&gt;42&lt;/span&gt;);
    &lt;span style="color: blue"&gt;var &lt;/span&gt;optionWithoutValue = &lt;span style="color: #2b91af"&gt;FSharpOption&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&amp;gt;.None;
    &lt;span style="color: blue"&gt;var &lt;/span&gt;isSome = &lt;span style="color: #2b91af"&gt;FSharpOption&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&amp;gt;.get_IsSome(optionWithValue);
    &lt;span style="color: blue"&gt;var &lt;/span&gt;isNone = &lt;span style="color: #2b91af"&gt;FSharpOption&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&amp;gt;.get_IsNone(optionWithValue);
    return optionWithValue.Value;
}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Too many explicit types!!!&amp;#160; Using any explicit type with F# related code just feels wrong.&amp;#160; &lt;/p&gt;

&lt;p&gt;In C#, and most other .Net languages, 4 out of the 5 operations you want to do on FSharpOption require an explicit type parameter.&amp;#160; This resulting code is a bit tedious with a simple type like int but once you get to more complex generics it can get extremely verbose.&amp;#160; In the case of anonymous types, it’s simply not possible to use the FSharpOption&amp;lt;T&amp;gt; without a few wrappers.&amp;#160; &lt;/p&gt;

&lt;p&gt;Luckily most of these can be solved by using the familiar pattern of using a non-generic class with static generic methods.&amp;#160; These allow C# users to take advantage of the languages type inference capabilities to reduce the verbosity of the code.&amp;#160; &lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public static class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;FSharpOption &lt;/span&gt;{
    &lt;span style="color: blue"&gt;public static &lt;/span&gt;&lt;span style="color: #2b91af"&gt;FSharpOption&lt;/span&gt;&amp;lt;T&amp;gt; Create&amp;lt;T&amp;gt;(T value) {
        &lt;span style="color: blue"&gt;return new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;FSharpOption&lt;/span&gt;&amp;lt;T&amp;gt;(value);
    }
    &lt;span style="color: blue"&gt;public static bool &lt;/span&gt;IsSome&amp;lt;T&amp;gt;(&lt;span style="color: blue"&gt;this &lt;/span&gt;&lt;span style="color: #2b91af"&gt;FSharpOption&lt;/span&gt;&amp;lt;T&amp;gt; opt) {
        &lt;span style="color: blue"&gt;return &lt;/span&gt;&lt;span style="color: #2b91af"&gt;FSharpOption&lt;/span&gt;&amp;lt;T&amp;gt;.get_IsSome(opt);
    }
    &lt;span style="color: blue"&gt;public static bool &lt;/span&gt;IsNone&amp;lt;T&amp;gt;(&lt;span style="color: blue"&gt;this &lt;/span&gt;&lt;span style="color: #2b91af"&gt;FSharpOption&lt;/span&gt;&amp;lt;T&amp;gt; opt) {
        &lt;span style="color: blue"&gt;return &lt;/span&gt;&lt;span style="color: #2b91af"&gt;FSharpOption&lt;/span&gt;&amp;lt;T&amp;gt;.get_IsNone(opt);
    }
}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Now we can rewrite the original sample a bit cleaner &lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;static int &lt;/span&gt;OptionExample() {
    &lt;span style="color: blue"&gt;var &lt;/span&gt;optionWithValue = &lt;span style="color: #2b91af"&gt;FSharpOption&lt;/span&gt;.Create(&lt;span style="color: brown"&gt;42&lt;/span&gt;);
    &lt;span style="color: blue"&gt;var &lt;/span&gt;optionWithoutValue = &lt;span style="color: #2b91af"&gt;FSharpOption&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&amp;gt;.None;
    &lt;span style="color: blue"&gt;var &lt;/span&gt;isSome = optionWithValue.IsSome();
    &lt;span style="color: blue"&gt;var &lt;/span&gt;isNone = optionWithoutValue.IsNone();
    &lt;span style="color: blue"&gt;return &lt;/span&gt;optionWithValue.Value;
}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Notice we still haven’t fixed the None case.&amp;#160; Fixing this is a beyond the scope of what I want to write here but it is possible in certain scenarios.&amp;#160; You can take a look at how in one of my previous blog articles: &lt;a href="http://blogs.msdn.com/jaredpar/archive/2008/10/06/functional-c-providing-an-option.aspx"&gt;Function C# Providing an Option&lt;/a&gt;.&amp;#160; &lt;/p&gt;

&lt;p&gt;This pattern is not just limited to the FSharpOption class but can be applied to many of the generic constructs F# exports to wrap their native types.&amp;#160; In particular FSharpFunc&amp;lt;T,Result&amp;gt; and the various FSharpChoice&amp;lt;&amp;gt; types can be made a bit friendlier with a few wrappers.&amp;#160; &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9937228" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jaredpar/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://blogs.msdn.com/jaredpar/archive/tags/Type+Inference/default.aspx">Type Inference</category><category domain="http://blogs.msdn.com/jaredpar/archive/tags/F_2300_/default.aspx">F#</category></item><item><title>Using F# Discriminated Unions in C# (Beta2)</title><link>http://blogs.msdn.com/jaredpar/archive/2009/10/27/using-f-discriminated-unions-in-c-beta2.aspx</link><pubDate>Tue, 27 Oct 2009 12:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9913363</guid><dc:creator>Jared Parsons</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/jaredpar/comments/9913363.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jaredpar/commentrss.aspx?PostID=9913363</wfw:commentRss><wfw:comment>http://blogs.msdn.com/jaredpar/rsscomments.aspx?PostID=9913363</wfw:comment><description>&lt;p&gt;While updating my VsVim editor extensions for Beta2 [1] I got hit by a change in the way F# exposed discriminated unions in metadata.&amp;#160; My extension consists of a core F# component with a corresponding set of unit tests written in C#.&amp;#160; It’s mostly API level testing and as such I use a lot of F# generated types in my C# test assembly.&lt;/p&gt;  &lt;p&gt;In Beta1 all information which could be extracted from a discriminated type union was immediately available on the value.&amp;#160; The underlying type presentation was less than desirable but these details were hidden by type inference and the very accessible API.&amp;#160;&amp;#160; The type wasn’t perfect because given a particular instance only the subset of the properties relevant to the union value type were valid.&amp;#160; All others threw exceptions.&amp;#160; But the code use of these methods and properties flowed very well.&amp;#160;&amp;#160; &lt;/p&gt;  &lt;p&gt;For instance take the following F# definition&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;type &lt;/span&gt;ActionKind =
    | Mouse = &lt;span style="color: brown"&gt;1
    &lt;/span&gt;| Keyboard = &lt;span style="color: brown"&gt;2

&lt;/span&gt;&lt;span style="color: blue"&gt;type &lt;/span&gt;ActionResult =
    | Complete &lt;span style="color: blue"&gt;of &lt;/span&gt;(ActionKind * int)
    | Error &lt;span style="color: blue"&gt;of &lt;/span&gt;string
    | NeedMore &lt;span style="color: blue"&gt;of &lt;/span&gt;(char &lt;span style="color: blue"&gt;-&amp;gt; &lt;/span&gt;ActionResult)&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;The use case in C# was quite simple&lt;/p&gt;

&lt;pre class="code"&gt;[&lt;span style="color: #2b91af"&gt;TestMethod&lt;/span&gt;]
&lt;span style="color: blue"&gt;public void &lt;/span&gt;TestActionBeta1(){
    &lt;span style="color: blue"&gt;var &lt;/span&gt;res = GetResult();
    &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.IsTrue(res.IsComplete());
    &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.AreEqual(&lt;span style="color: #2b91af"&gt;ActionKind&lt;/span&gt;.Mouse, res.Complete1.Item1);
    &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.AreEqual(&lt;span style="color: brown"&gt;42&lt;/span&gt;, res.Complete1.Item2);
}&lt;/pre&gt;

&lt;p&gt;Notice how no type information is necessary and the code flows quite naturally.&amp;#160; C# type inference works great here and allows me to do what I need to do without fussing around with little stuff.&amp;#160; The type in this case is a detail I don’t need to know about.&amp;#160; It simply adds no value.&amp;#160; &lt;/p&gt;

&lt;p&gt;Discriminated Unions in Beta2 changed substantially in this area.&amp;#160; Instead of generating the set of all values on the exposed type, there is now an inner type generated for every discriminated union value and the properties relevant to that union value are stored on the inner type.&amp;#160; The outer type now contains only properties to determine which type of value it is (certainly an upgrade from methods!) [2]&lt;/p&gt;

&lt;p&gt;For instance in the case of ActionResult there are 3 generated inner classes: Complete, Error and NeedMore.&amp;#160; Each one contains a single property Item which contains the associated value(s).&amp;#160; This means to get to the value portion a cast to the inner type must be inserted!&amp;#160; &lt;/p&gt;

&lt;p&gt;Lets take a a look at how the above test code has to change to deal with the Beta2 generation of ActionResult.&amp;#160; &lt;/p&gt;

&lt;pre class="code"&gt;[&lt;span style="color: #2b91af"&gt;TestMethod&lt;/span&gt;]
&lt;span style="color: blue"&gt;public void &lt;/span&gt;TestActionBeta2() {
    &lt;span style="color: blue"&gt;var &lt;/span&gt;res = GetResult();
    &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.IsTrue(res.IsComplete);
    &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.AreEqual(&lt;span style="color: #2b91af"&gt;ActionKind&lt;/span&gt;.Mouse, ((&lt;span style="color: #2b91af"&gt;ActionResult&lt;/span&gt;.&lt;span style="color: #2b91af"&gt;Complete&lt;/span&gt;)res).Item.Item1);
    &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.AreEqual(&lt;span style="color: brown"&gt;42&lt;/span&gt;, ((&lt;span style="color: #2b91af"&gt;ActionResult&lt;/span&gt;.&lt;span style="color: #2b91af"&gt;Complete&lt;/span&gt;)res).Item.Item2);
}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Notice the explicit casts which must be added to access the values.&amp;#160; This makes it impossible to rely soley on C# type inference.&amp;#160; I must now understand the underlying type structure of discriminated unions in order to use them.&amp;#160; This extra cast adds no real value to my code.&amp;#160; &lt;/p&gt;

&lt;p&gt;My C# test assembly has literally hundreds of test cases which use this pattern on F# types.&amp;#160; I didn’t know the return type of every method and found myself hitting “Goto Def” on a lot of “var” instances to discover the static type, going back to the original file and inserting the cast.&amp;#160; It was a tedious and slow process.&lt;/p&gt;

&lt;p&gt;Eventually I settled on a different solution.&amp;#160; For every type I exposed in F# I added a set of extension methods in the form of AsXXX where XXX represented the name of the generated inner types.&amp;#160;&amp;#160; For example&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public static &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ActionResult&lt;/span&gt;.&lt;span style="color: #2b91af"&gt;Complete &lt;/span&gt;AsComplete(&lt;span style="color: blue"&gt;this &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ActionResult &lt;/span&gt;res) {
    &lt;span style="color: blue"&gt;return &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;ActionResult&lt;/span&gt;.&lt;span style="color: #2b91af"&gt;Complete&lt;/span&gt;)res;
}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;The advantage of this approach is 2 fold &lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Removes the need to explicitly name types in code and hence gets back the advantages of type inference&lt;/li&gt;

  &lt;li&gt;I can now use . on any of the values and let Intellisense help me find the appropriate method to use&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This extension method allows me to get closer to the Beta1 style code &lt;/p&gt;

&lt;pre class="code"&gt;[&lt;span style="color: #2b91af"&gt;TestMethod&lt;/span&gt;]
&lt;span style="color: blue"&gt;public void &lt;/span&gt;TestActionBeta2() {
    &lt;span style="color: blue"&gt;var &lt;/span&gt;res = GetResult();
    &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.IsTrue(res.IsComplete);
    &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.AreEqual(&lt;span style="color: #2b91af"&gt;ActionKind&lt;/span&gt;.Mouse, res.AsComplete().Item.Item1);
    &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.AreEqual(&lt;span style="color: brown"&gt;42&lt;/span&gt;, res.AsComplete().Item.Item2);
}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;With these methods and a quick series of Find / Replace calls, I was back in business.&amp;#160; &lt;/p&gt;

&lt;p&gt;[1] It’s coming I promise!&amp;#160; &lt;/p&gt;

&lt;p&gt;[2] It also contains a handy set of factory methods for generating values but it’s not relevant to this discussion.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9913363" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jaredpar/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://blogs.msdn.com/jaredpar/archive/tags/Extension+Methods/default.aspx">Extension Methods</category><category domain="http://blogs.msdn.com/jaredpar/archive/tags/Type+Inference/default.aspx">Type Inference</category><category domain="http://blogs.msdn.com/jaredpar/archive/tags/F_2300_/default.aspx">F#</category></item><item><title>Vim Emulator Editor Extension Released</title><link>http://blogs.msdn.com/jaredpar/archive/2009/09/08/vim-emulator-editor-extension-released.aspx</link><pubDate>Wed, 09 Sep 2009 05:09:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9863823</guid><dc:creator>Jared Parsons</dc:creator><slash:comments>17</slash:comments><comments>http://blogs.msdn.com/jaredpar/comments/9863823.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jaredpar/commentrss.aspx?PostID=9863823</wfw:commentRss><wfw:comment>http://blogs.msdn.com/jaredpar/rsscomments.aspx?PostID=9863823</wfw:comment><description>&lt;p&gt;I just released version 0.5.0 of VsVim: a vim emulation editor extension for Visual Studio 2010 Beta1 written in F#.&amp;nbsp; This is a hobby project I’ve been working on for awhile now.&amp;nbsp; I expect to continue updating this release as time goes on as I use it on a daily basis and I’m interested in getting back feedback from users on it.&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Link:&amp;nbsp;&lt;a href="http://visualstudiogallery.msdn.microsoft.com/en-us/59ca71b3-a4a3-46ca-8fe1-0e90e3f79329"&gt;http://visualstudiogallery.msdn.microsoft.com/en-us/59ca71b3-a4a3-46ca-8fe1-0e90e3f79329&lt;/a&gt;&amp;nbsp;&lt;/p&gt;  &lt;p&gt;Here’s a quick break down on the state of this project&lt;/p&gt;  &lt;p align="left"&gt;&lt;b&gt;Caveats and Expectations&lt;/b&gt;&lt;/p&gt;  &lt;p align="left"&gt;This extension is being released by me, not by Microsoft.&amp;nbsp; As such the support level for this extension is equivalent to the amount of free time I have to put into it.&amp;nbsp; &lt;/p&gt;  &lt;p&gt;&lt;b&gt;Quality Level&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;I would classify this as a Beta style release.&amp;nbsp; I use this extension every day and I have a very large test bed to verify functionality.&amp;nbsp; There are still several known bugs (detailed below) and little quirks I’m working on.&amp;nbsp; But they are mostly minor issues&lt;/p&gt;  &lt;p&gt;&lt;b&gt;What’s Implemented&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;At this point the engine has an Insert, Normal and Command mode.&amp;nbsp; &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="left"&gt;Insert Mode&lt;/div&gt;      &lt;ul&gt;       &lt;li&gt;         &lt;div align="left"&gt;Basic insertion layer which allows for typing.&amp;nbsp; No special insert mode commands are implemented &lt;/div&gt;       &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="left"&gt;Normal Mode.&lt;/div&gt;      &lt;ul&gt;       &lt;li&gt;Movement Commands: h,j,k,l,w,b,$,^,n,*,# &lt;/li&gt;        &lt;li&gt;Edit Commands: x,X,d,p,P,A,u,&amp;lt;,&amp;gt;,o &lt;/li&gt;        &lt;li&gt;Incremental Search &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="left"&gt;Command Mode&lt;/div&gt;      &lt;ul&gt;       &lt;li&gt;         &lt;div align="left"&gt;:e&lt;/div&gt;       &lt;/li&gt;        &lt;li&gt;         &lt;div align="left"&gt;Jump to line&lt;/div&gt;       &lt;/li&gt;        &lt;li&gt;         &lt;div align="left"&gt;Beginning / end of line&lt;/div&gt;       &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p align="left"&gt;&lt;b&gt;Deviations &lt;/b&gt;&lt;/p&gt;  &lt;p align="left"&gt;The biggest deviation I made from a traditional VIM engine is that I am using .Net regular expressions instead of VIM style regular expressions.&amp;nbsp; This allowed me to focus on getting a lot of features written vs. spending time building a regular expression engine.&amp;nbsp; Getting this working will be a focus of a later release.&amp;nbsp; &lt;/p&gt;  &lt;p align="left"&gt;Another issue is the cursor.&amp;nbsp; As flexible as the new editor is, one part that is very tricky is changing the appearance of the cursor.&amp;nbsp; So making a block style cursor for normal mode was not done for this release.&amp;nbsp; Instead I simply color the cursor red for normal mode and black for insert mode.&amp;nbsp; This will be fixed in a later release.&lt;/p&gt;  &lt;p align="left"&gt;&lt;b&gt;Bugs&lt;/b&gt;&lt;/p&gt;  &lt;p align="left"&gt;Below is the list of known issues for the extension.&amp;nbsp; I’ve noted all bugs for which I cannot get a steady repro.&amp;nbsp; If you can find one I would appreciate you emailing the steps to me.&amp;nbsp; &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="left"&gt;Cursor appearance in normal mode is not a block cursor but instead a red cursor &lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;Need Repro: Using ‘o’ in normal mode can cause the line ending to switch from \r\n to \r or \n. &lt;/li&gt;    &lt;li&gt;     &lt;div align="left"&gt;Both ‘#’ and ‘*’ match partial words instead of full words&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="left"&gt;Register list is limited to standard a-z alphabet &lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p align="left"&gt;&lt;b&gt;What’s next?&lt;/b&gt;&lt;/p&gt;  &lt;p align="left"&gt;Thus far I’ve been working on features which don’t conflict with existing Visual Studio key bindings.&amp;nbsp; The next big release will be focusing on the infrastructure needed to integrate these commands smoothly into the core Vim engine and Visual Studio itself.&amp;nbsp; This will allow me to expand the number of implemented features a great deal.&amp;nbsp; &lt;/p&gt;  &lt;p align="left"&gt;&lt;b&gt;Where’s the source?&lt;/b&gt;&lt;/p&gt;  &lt;p align="left"&gt;Should be released soon.&amp;nbsp; Right now I’m working out where I should host this project long term.&amp;nbsp; Preferably a place where users can file bugs and leave feedback.&amp;nbsp; &lt;/p&gt;  &lt;p align="left"&gt;&lt;br&gt;&lt;/p&gt;  &lt;p align="left"&gt;&amp;nbsp;&lt;/p&gt;  &lt;p align="left"&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9863823" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jaredpar/archive/tags/F_2300_/default.aspx">F#</category><category domain="http://blogs.msdn.com/jaredpar/archive/tags/VsVim/default.aspx">VsVim</category></item><item><title>Mapping LINQ to F#</title><link>http://blogs.msdn.com/jaredpar/archive/2008/12/02/mapping-linq-to-f.aspx</link><pubDate>Tue, 02 Dec 2008 16:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9162978</guid><dc:creator>Jared Parsons</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/jaredpar/comments/9162978.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jaredpar/commentrss.aspx?PostID=9162978</wfw:commentRss><wfw:comment>http://blogs.msdn.com/jaredpar/rsscomments.aspx?PostID=9162978</wfw:comment><description>&lt;p&gt;In my projects with F#, I often find that I know exactly what type of sequence transformation I want to run, yet I spend all of my time trying to find it!!!&amp;#160; The problem is I’m used to query comprehensions in LINQ terminology.&amp;#160; Select, Where and SelectMany are so ingrained into my programming they are practically done through muscle memory.&amp;#160; &lt;/p&gt;  &lt;p&gt;Unfortunately there is a disconnect between the naming convention used in LINQ and the ones used in F#.&amp;#160; Some of the names are more intuitive than others.&amp;#160; I’ve now spent enough time digging through Seq.fs that it’s time to draw up a table that maps various LINQ functions to their equivalent method in F#.&amp;#160; &lt;/p&gt;  &lt;p&gt;If nothing else, it will be a good table for me to come back to.&amp;#160; Below is a list of many methods in &lt;a href="http://msdn.microsoft.com/en-us/library/system.linq.enumerable_methods.aspx"&gt;Enumerable&lt;/a&gt;, mapped to the equivalent function in F#’s seq&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Aggregate –&amp;gt; fold&lt;/li&gt;    &lt;li&gt;All –&amp;gt; for_all&lt;/li&gt;    &lt;li&gt;Any –&amp;gt; exists&lt;/li&gt;    &lt;li&gt;Average –&amp;gt; average&lt;/li&gt;    &lt;li&gt;Cast –&amp;gt; cast&lt;/li&gt;    &lt;li&gt;Count –&amp;gt; length&lt;/li&gt;    &lt;li&gt;Distinct –&amp;gt; distinct&lt;/li&gt;    &lt;li&gt;ElementAt –&amp;gt; nth&lt;/li&gt;    &lt;li&gt;Empty –&amp;gt; empty&lt;/li&gt;    &lt;li&gt;First –&amp;gt; hd&lt;/li&gt;    &lt;li&gt;GroupBy –&amp;gt; group_by&lt;/li&gt;    &lt;li&gt;Max –&amp;gt; max&lt;/li&gt;    &lt;li&gt;Min –&amp;gt; min&lt;/li&gt;    &lt;li&gt;OrderBy –&amp;gt; sort_by&lt;/li&gt;    &lt;li&gt;Select –&amp;gt; map, mapi&lt;/li&gt;    &lt;li&gt;SelectMany –&amp;gt; concat, map_concat&lt;/li&gt;    &lt;li&gt;SequenceEqual –&amp;gt; compare&lt;/li&gt;    &lt;li&gt;Skip –&amp;gt; skip&lt;/li&gt;    &lt;li&gt;SkipWhile –&amp;gt; skip_while&lt;/li&gt;    &lt;li&gt;Sum –&amp;gt; sum&lt;/li&gt;    &lt;li&gt;Where –&amp;gt; filter&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Below are the functions for which an equivalent was not found (or was quite simply overlooked).&amp;#160; Most of these can be added with a combination of other simple transformations. &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;DefaultIfEmpty&lt;/li&gt;    &lt;li&gt;Except&lt;/li&gt;    &lt;li&gt;FirstOrDefault&lt;/li&gt;    &lt;li&gt;GroupJoin&lt;/li&gt;    &lt;li&gt;Intersect&lt;/li&gt;    &lt;li&gt;Join&lt;/li&gt;    &lt;li&gt;Last&lt;/li&gt;    &lt;li&gt;LastOrDefault&lt;/li&gt;    &lt;li&gt;LongCount&lt;/li&gt;    &lt;li&gt;OfType&lt;/li&gt;    &lt;li&gt;Reverse&lt;/li&gt;    &lt;li&gt;Single&lt;/li&gt;    &lt;li&gt;SingleOrDefault&lt;/li&gt;    &lt;li&gt;Union&lt;/li&gt; &lt;/ul&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9162978" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jaredpar/archive/tags/F_2300_/default.aspx">F#</category><category domain="http://blogs.msdn.com/jaredpar/archive/tags/LINQ/default.aspx">LINQ</category></item><item><title>Comparing Continuations in C# and F# Part 3: Double wrong</title><link>http://blogs.msdn.com/jaredpar/archive/2008/11/13/comparing-continuations-in-c-and-f-part-3-double-wrong.aspx</link><pubDate>Thu, 13 Nov 2008 16:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9064743</guid><dc:creator>Jared Parsons</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/jaredpar/comments/9064743.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jaredpar/commentrss.aspx?PostID=9064743</wfw:commentRss><wfw:comment>http://blogs.msdn.com/jaredpar/rsscomments.aspx?PostID=9064743</wfw:comment><description>&lt;p&gt;Is it better to be wrong once or to be right then think you’re wrong but find out you were right but wrong about being wrong? Besides the obvious be right the first time, it’s certainly an educational experience.&amp;#160; &lt;/p&gt;  &lt;p&gt;Here’s the original sample:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;let &lt;/span&gt;FoldRight combine (sequence:seq&amp;lt;'a&amp;gt;) acc = 
    &lt;span style="color: blue"&gt;use &lt;/span&gt;e = sequence.GetEnumerator()
    &lt;span style="color: blue"&gt;let rec &lt;/span&gt;inner cont = 
        &lt;span style="color: blue"&gt;match &lt;/span&gt;e.MoveNext() &lt;span style="color: blue"&gt;with
            &lt;/span&gt;| &lt;span style="color: blue"&gt;true -&amp;gt; 
                let &lt;/span&gt;cur = e.Current
                inner (&lt;span style="color: blue"&gt;fun &lt;/span&gt;racc &lt;span style="color: blue"&gt;-&amp;gt; &lt;/span&gt;cont (combine cur racc))
            | &lt;span style="color: blue"&gt;false -&amp;gt; &lt;/span&gt;cont acc
    inner (&lt;span style="color: blue"&gt;fun &lt;/span&gt;x &lt;span style="color: blue"&gt;-&amp;gt; &lt;/span&gt;x )&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;a href="http://lorgonblog.spaces.live.com/blog/"&gt;Brian McNamara&lt;/a&gt; pointed out I wasn’t considering all of the call sites for this sample.&amp;#160; In addition to the recursive call to “inner” and the initial inner call, there is the actual recursive invocation of the of the continuations.&amp;#160; Effectively the “inner” function is building up a list of list of lambdas which call the combine function.&amp;#160; The output of the combine function is simply passed into the next lambda in the list.&amp;#160; The last lambda in the list is the identity lambda and returns the final call to combine.&amp;#160; This value is the actual value returned from the initial invocation “cont acc”.&amp;#160; Lambdas are methods under the hood.&amp;#160; Without a tail instruction, this chain of lambda calls will just as easily overflow the stack.&lt;/p&gt;

&lt;p&gt;Digging deeper into the compiled F# code we can view this call and indeed it is done with tail recursion.&amp;#160; &lt;/p&gt;

&lt;pre class="code"&gt; 
.method public virtual instance !V Invoke(!U racc) cil managed
{
    .maxstack 8
    L_0000: nop 
    L_0001: ldarg.0 
    L_0002: ldfld class [FSharp.Core]Microsoft.FSharp.Core.FastFunc`2&lt;!0, !1&gt; Program/clo@9&lt;!U, !V, !A&gt;::cont
    L_0007: ldarg.0 
    L_0008: ldfld class [FSharp.Core]Microsoft.FSharp.Core.FastFunc`2&lt;!2, class [FSharp.Core]Microsoft.FSharp.Core.FastFunc`2&lt;!0, !0&gt;&amp;gt; Program/clo@9&lt;!U, !V, !A&gt;::combine
    L_000d: ldarg.0 
    L_000e: ldfld !2 Program/clo@9&lt;!U, !V, !A&gt;::cur
    L_0013: ldarg.1 
    L_0014: call !!0 [FSharp.Core]Microsoft.FSharp.Core.FastFunc`2&lt;!A, !U&gt;::InvokeFast2&lt;!U&gt;(class [FSharp.Core]Microsoft.FSharp.Core.FastFunc`2&lt;!0, class [FSharp.Core]Microsoft.FSharp.Core.FastFunc`2&lt;!1, !!0&gt;&amp;gt;, !0, !1)
    L_0019: tail 
    L_001b: callvirt instance !1 [FSharp.Core]Microsoft.FSharp.Core.FastFunc`2&lt;!U, !V&gt;::Invoke(!0)
    L_0020: ret 
}&lt;/pre&gt;

&lt;p&gt;The below code more accurately resembles the equivalent C# code that is generated for the above F# sample&amp;#160; (thanks Brian!).&amp;#160; &lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public static &lt;/span&gt;TAcc Inner&amp;lt;TSource, TAcc&amp;gt;(
    &lt;span style="color: blue"&gt;this &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IEnumerator&lt;/span&gt;&amp;lt;TSource&amp;gt; e,
    &lt;span style="color: #2b91af"&gt;Func&lt;/span&gt;&amp;lt;TAcc, TSource, TAcc&amp;gt; combine,
    TAcc start,
    &lt;span style="color: #2b91af"&gt;Func&lt;/span&gt;&amp;lt;TAcc, TAcc&amp;gt; cont)
{
    &lt;span style="color: blue"&gt;while &lt;/span&gt;(e.MoveNext())
    {
        &lt;span style="color: blue"&gt;var &lt;/span&gt;cur = e.Current;
        &lt;span style="color: #2b91af"&gt;Func&lt;/span&gt;&amp;lt;TAcc, TAcc&amp;gt; innerCont = cont;
        cont = (x) =&amp;gt; &lt;span style="color: green"&gt;/*need .tail here */&lt;/span&gt;innerCont(combine(x, cur));
    }
    &lt;span style="color: blue"&gt;return &lt;/span&gt;cont(start);
}

&lt;span style="color: blue"&gt;public static &lt;/span&gt;TAcc FoldRight&amp;lt;TSource, TAcc&amp;gt;(
    &lt;span style="color: blue"&gt;this &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IEnumerable&lt;/span&gt;&amp;lt;TSource&amp;gt; enumerable,
    &lt;span style="color: #2b91af"&gt;Func&lt;/span&gt;&amp;lt;TAcc, TSource, TAcc&amp;gt; combine,
    TAcc start)
{
    &lt;span style="color: blue"&gt;using &lt;/span&gt;(&lt;span style="color: blue"&gt;var &lt;/span&gt;e = enumerable.GetEnumerator())
    {
        &lt;span style="color: blue"&gt;return &lt;/span&gt;Inner(e, combine, start, (x) =&amp;gt; x);
    }
}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;strong&gt;Previous Entries&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href="http://blogs.msdn.com/jaredpar/archive/2008/11/10/comparing-continuations-in-f-and-c.aspx"&gt;Part 1&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://blogs.msdn.com/jaredpar/archive/2008/11/11/comparing-continuations-in-c-and-f-part-2.aspx"&gt;Part 2&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9064743" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jaredpar/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://blogs.msdn.com/jaredpar/archive/tags/F_2300_/default.aspx">F#</category></item><item><title>Comparing Continuations in C# and F# Part 2</title><link>http://blogs.msdn.com/jaredpar/archive/2008/11/11/comparing-continuations-in-c-and-f-part-2.aspx</link><pubDate>Tue, 11 Nov 2008 19:38:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9060458</guid><dc:creator>Jared Parsons</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/jaredpar/comments/9060458.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jaredpar/commentrss.aspx?PostID=9060458</wfw:commentRss><wfw:comment>http://blogs.msdn.com/jaredpar/rsscomments.aspx?PostID=9060458</wfw:comment><description>&lt;P&gt;In my last post I went over the differences between using a &lt;A href="http://blogs.msdn.com/jaredpar/archive/2008/11/10/comparing-continuations-in-f-and-c.aspx" mce_href="http://blogs.msdn.com/jaredpar/archive/2008/11/10/comparing-continuations-in-f-and-c.aspx"&gt;continuation in F# and C#&lt;/A&gt;.&amp;nbsp; As it turns out I was right about the limits and symptoms but wrong about the reason.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;The F# code does indeed generate tail calls for part of the continuation.&amp;nbsp; However this is only a very small portion of the actual code and is in fact only generated for the call in the empty case.&amp;nbsp; I misread this function to be the call for the overall continuation.&amp;nbsp; Instead it is the function for the entire “inner” lambda. &lt;/P&gt;
&lt;P&gt;So why does F# perform differently than C# in this scenario? &lt;/P&gt;
&lt;P&gt;Andrew Kennedy pointed out that F# will actually transform the “inner” function into a loop.&amp;nbsp; In affect the code generated looks like the following. &lt;/P&gt;&lt;PRE&gt;    TypeFunc func = this._self3;
    while (true)
    {
        if (!this.e.MoveNext())
        {
            break;
        }
        A cur = this.e.Current;
        cont = new Program.clo@9&amp;lt;U V, A ,&amp;gt;(this.combine, cont, cur);
    }
    return cont.Invoke(this.acc);&lt;/PRE&gt;
&lt;P&gt;The actual transformation into a loop is what is preventing F# from overflowing the stack here.&amp;nbsp; Iteration incurs no stack overhead in this case.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Even more interesting is that the &lt;A href="http://msdn.microsoft.com/en-us/library/system.reflection.emit.opcodes.tailcall(VS.71).aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.reflection.emit.opcodes.tailcall(VS.71).aspx"&gt;tail opcode&lt;/A&gt; is quite simply ignored when dealing with un-trusted code.&amp;nbsp; It therefore cannot be relied on to generate performant code in all scenarios.&amp;nbsp; &lt;/P&gt;&lt;/U&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9060458" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jaredpar/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://blogs.msdn.com/jaredpar/archive/tags/F_2300_/default.aspx">F#</category></item><item><title>Comparing Continuations in F# and C#</title><link>http://blogs.msdn.com/jaredpar/archive/2008/11/10/comparing-continuations-in-f-and-c.aspx</link><pubDate>Mon, 10 Nov 2008 16:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9056481</guid><dc:creator>Jared Parsons</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/jaredpar/comments/9056481.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jaredpar/commentrss.aspx?PostID=9056481</wfw:commentRss><wfw:comment>http://blogs.msdn.com/jaredpar/rsscomments.aspx?PostID=9056481</wfw:comment><description>&lt;p&gt;Lately I’ve been playing quite a bit with F#.&amp;#160; I have several hobby projects I’m working on that take up a bit of my time.&amp;#160; But when I’m not playing around with F# I’m exploring ways to apply certain functional patterns to actual coding on the job and/or porting to my functional library: &lt;a href="http://code.msdn.microsoft.com/RantPack"&gt;RantPack&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Recently I’ve been playing around with continuations in F#.&amp;#160; I thought this was a great topic to do a F# comparison with other languages.&amp;#160; In this case C#.&amp;#160; &lt;/p&gt;  &lt;p&gt;Let’s examine a classic use of continuations: a right fold on a list.&amp;#160; For a detailed explanation of fold right and the use of a continuation I suggest taking a look at &lt;a href="http://lorgonblog.spaces.live.com/blog/cns!701679AD17B6D310!170.entry"&gt;Brian's discussion&lt;/a&gt;.&amp;#160; If you’re unfamiliar with continuations I highly suggest that you take a look at this post as Brian gives a great breakdown of continuations and their uses.&lt;/p&gt;  &lt;p&gt;Here's a quick refresher on continuations by example.&amp;#160; Fold right is an operation which reduces a sequence of elements into a single element by processing the list from right to left.&amp;#160; It’s similar to the &lt;a href="http://msdn.microsoft.com/en-us/library/system.linq.enumerable.aggregate.aspx"&gt;LINQ Aggregate&lt;/a&gt; method except Aggregate operations left to right.&amp;#160; &lt;/p&gt;  &lt;p&gt;For this post we’ll be writing FoldRight against a sequence.&amp;#160; I chose sequence vs. the traditional list because it’s present in both languages (F# = seq&amp;lt;’a&amp;gt;, C# = IEnumerable&amp;lt;T&amp;gt;).&amp;#160; It is possible to other F# data structures in C# but the comparison is cleaner when using a type that is native to both languages. &lt;/p&gt;  &lt;p&gt;Sequences are a left to right data structure so processing it right to left is not natural.&amp;#160; After all, with a sequence all the developer has is current and whether or not there is a next element.&amp;#160; Processing the list in a right to left fashion can be done by such acts as reversing the list, or doing a head recursive call.&amp;#160; Both have their detractors. &lt;/p&gt;  &lt;p&gt;Continuations are a different way to process the list.&amp;#160; Instead of processing the list directly we process the list a single element at a time building up a continuation along the way.&amp;#160; For each element a lambda expression is generated representing the work needed to be done for that element.&amp;#160; The value calculated within the lambda will then be passed to the lambda calculated for the previous element.&amp;#160; Once we hit the end of the list, we essentially have a chain of lambda expressions which process each element in the list in reverse order.&amp;#160; All that is needed is to call the final lambda with the starting value and we will effectively process the list in reverse order.&lt;/p&gt;  &lt;p&gt;Simple enough?&amp;#160; Lets take a look at the code.&amp;#160; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;F# Code&lt;/strong&gt;&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;let &lt;/span&gt;FoldRight combine (sequence:seq&amp;lt;'a&amp;gt;) acc = 
    &lt;span style="color: blue"&gt;use &lt;/span&gt;e = sequence.GetEnumerator()
    &lt;span style="color: blue"&gt;let rec &lt;/span&gt;inner cont = 
        &lt;span style="color: blue"&gt;match &lt;/span&gt;e.MoveNext() &lt;span style="color: blue"&gt;with
            &lt;/span&gt;| &lt;span style="color: blue"&gt;true -&amp;gt; 
                let &lt;/span&gt;cur = e.Current
                inner (&lt;span style="color: blue"&gt;fun &lt;/span&gt;racc &lt;span style="color: blue"&gt;-&amp;gt; &lt;/span&gt;cont (combine cur racc))
            | &lt;span style="color: blue"&gt;false -&amp;gt; &lt;/span&gt;cont acc
    inner (&lt;span style="color: blue"&gt;fun &lt;/span&gt;x &lt;span style="color: blue"&gt;-&amp;gt; &lt;/span&gt;x )&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;C# Code&lt;/strong&gt;&amp;#160;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public static &lt;/span&gt;TAcc FoldRight&amp;lt;TSource, TAcc&amp;gt;(
    &lt;span style="color: blue"&gt;this &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IEnumerable&lt;/span&gt;&amp;lt;TSource&amp;gt; enumerable, 
    &lt;span style="color: #2b91af"&gt;Func&lt;/span&gt;&amp;lt;TAcc, TSource, TAcc&amp;gt; combine, 
    TAcc start) {

    &lt;span style="color: blue"&gt;using &lt;/span&gt;(&lt;span style="color: blue"&gt;var &lt;/span&gt;e = enumerable.GetEnumerator()) {
        &lt;span style="color: #2b91af"&gt;Func&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Func&lt;/span&gt;&amp;lt;TAcc, TAcc&amp;gt;, TAcc&amp;gt; inner = &lt;span style="color: blue"&gt;null&lt;/span&gt;;
        inner = (cont) =&amp;gt; {
              &lt;span style="color: blue"&gt;if &lt;/span&gt;(e.MoveNext()) {
                  &lt;span style="color: blue"&gt;var &lt;/span&gt;cur = e.Current;
                  &lt;span style="color: #2b91af"&gt;Func&lt;/span&gt;&amp;lt;TAcc, TAcc&amp;gt; innerCont = (x) =&amp;gt; cont(combine(x, cur));
                  &lt;span style="color: blue"&gt;return &lt;/span&gt;inner(innerCont);
              } &lt;span style="color: blue"&gt;else &lt;/span&gt;{
                  &lt;span style="color: blue"&gt;return &lt;/span&gt;cont(start);
              }
          };
        &lt;span style="color: blue"&gt;return &lt;/span&gt;inner(x =&amp;gt; x);
    }
}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;My immediate reaction to the two samples is the conciseness of the F# code.&amp;#160; This is a not a criticism of C# though.&amp;#160; F# is designed to be a concise language and it’s delivery on that goal is evident in this sample.&amp;#160; &lt;/p&gt;

&lt;p&gt;What makes the big difference here is the type inference power of F#.&amp;#160; In the C# sample there are 6 explicit types listed in the code sample.&amp;#160; The F# sample only has a single type listed.&amp;#160; The compiler is able to infer and/or generate the rest of the signatures.&amp;#160; F# also requires less explicit generic parameters 1 vs. 2 in C#.&lt;/p&gt;

&lt;p&gt;The next big difference I see is the awkward way in which the inner lambda expression must be declared in C#.&amp;#160; The lambda expression is called recursively in order to setup the continuation.&amp;#160; In order to do that in C# the lambda must be declared and defined in separate expressions.&amp;#160; Otherwise, a self reference of “inner” inside the body of “inner” will generate a used before defined warning from the compiler.&amp;#160; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The IL&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Examining the full IL of both functions would take several blog posts.&amp;#160; Not to mention that trying to read disassembled F# much less IL, is like trying to read disassembled C++.&amp;#160; An interesting exercise but a bit time consuming.&amp;#160; &lt;/p&gt;

&lt;p&gt;I did want to focus a bit on one portion of the generated IL.&amp;#160; There is a very significant difference in the way the recursive call to the “inner” lambda is made.&amp;#160; &lt;/p&gt;

&lt;p&gt;F#&lt;/p&gt;

&lt;pre class="code"&gt;    L_0032: ldarg.1 
    L_0033: ldarg.0 
    L_0034: ldfld !0 Test/clo@6T&lt;!U, !A, !V&gt;::acc
    L_0039: tail 
    L_003b: callvirt instance !1 [FSharp.Core]Microsoft.FSharp.Core.FastFunc`2&lt;!U, !V&gt;::Invoke(!0)&lt;/pre&gt;

&lt;p&gt;C#&lt;/p&gt;

&lt;pre class="code"&gt;    
    L_0077: ldarg.0 
    L_0078: ldfld class [System.Core]System.Func`2&lt;class  !1 [System.Core]System.Func`2&gt;&lt;!1,&gt;, !1&amp;gt; ConsoleApplication1.Extensions/&amp;lt;&amp;gt;c__DisplayClass8&lt;!TSource, !TAcc&gt;::inner
    L_007d: ldloc.0 
    L_007e: callvirt instance !1 [System.Core]System.Func`2&lt;class  !TAcc [System.Core]System.Func`2&gt;&lt;!TAcc,&gt;, !TAcc&amp;gt;::Invoke(!0)
    L_0083: stloc.3 &lt;/pre&gt;

&lt;p&gt;In both cases the first 3 lines are building up the 2 parameters necessary for the recursive lambda call.&amp;#160; The closures are structured somewhat differently but the same basic operation is being done.&amp;#160; &lt;/p&gt;

&lt;p&gt;The key difference between the languages is F#’s use of the &lt;a href="http://msdn.microsoft.com/en-us/library/system.reflection.emit.opcodes.tailcall(VS.95).aspx"&gt;tail opcode&lt;/a&gt;.&amp;#160; This opcode tells the CLR the to call the next method in a tail recursive fashion.&amp;#160; This causes the CLR to remove the current method frame from the stack before the next method is called.&amp;#160; Because the method is removed from the stack, the recursive call takes up no additional stack space.&amp;#160; This is true no matter how many times the function is called.&lt;/p&gt;

&lt;p&gt;The C# IL does not have this opcode.&amp;#160; So the recursive call will happen with the current method on the frame.&amp;#160; With a big enough sequence this will cause the process to run out of stack space and generate a StackOverflowException.&amp;#160; This creates a limitation on the number of elements the C# sample can process.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Limits&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I explored the limits of both samples on my home laptop.&amp;#160; I generated a simple example to sum the sequence with the fold right.&amp;#160; Note: For a sum of ints, a fold left is just as good, but it serves fine for this sample.&lt;/p&gt;

&lt;p&gt;F#&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;let &lt;/span&gt;sum = FoldRight (&lt;span style="color: blue"&gt;fun &lt;/span&gt;x y &lt;span style="color: blue"&gt;-&amp;gt; &lt;/span&gt;x + y) [1..1000000] 0
printfn &lt;span style="color: maroon"&gt;&amp;quot;%d&amp;quot; &lt;/span&gt;sum&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;C#&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;source = &lt;span style="color: #2b91af"&gt;Enumerable&lt;/span&gt;.Range(1, 9397);
&lt;span style="color: blue"&gt;var &lt;/span&gt;result = source.FoldRight((x, y) =&amp;gt; x + y, 0);
&lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;&amp;quot;{0}&amp;quot;&lt;/span&gt;, result);&lt;/pre&gt;

&lt;p&gt;The C# sample can process a maximum size of 9397 elements.&amp;#160; After that I encounter a stackoverflow exception. The F# sample however can easily process 1,000,000 elements. &lt;/p&gt;

&lt;p&gt;Closing note.&amp;#160; This not meant to be a post criticizing C#.&amp;#160; It’s meant to be a general comparison of the same technique in two managed languages.&amp;#160; This is a scenario that is far less likely to occur in a C# program.&amp;#160; In an F# program it’s quite simply an expectation and hence the F# compiler is optimized for this scenario.&amp;#160; &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9056481" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jaredpar/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://blogs.msdn.com/jaredpar/archive/tags/Patterns/default.aspx">Patterns</category><category domain="http://blogs.msdn.com/jaredpar/archive/tags/F_2300_/default.aspx">F#</category></item><item><title>Functional C#: Providing an Option Part 2</title><link>http://blogs.msdn.com/jaredpar/archive/2008/10/08/functional-c-providing-an-option-part-2.aspx</link><pubDate>Wed, 08 Oct 2008 15:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8987105</guid><dc:creator>Jared Parsons</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/jaredpar/comments/8987105.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jaredpar/commentrss.aspx?PostID=8987105</wfw:commentRss><wfw:comment>http://blogs.msdn.com/jaredpar/rsscomments.aspx?PostID=8987105</wfw:comment><description>&lt;p&gt;In my &lt;a href="http://blogs.msdn.com/jaredpar/archive/2008/10/06/functional-c-providing-an-option.aspx"&gt;previous post&lt;/a&gt; I discussed creating an Option style construct for C#/.Net.&amp;#160; This post is a followup with the complete code snippet.&amp;#160; It’s been updated in response to several bits of feedback I received.&amp;#160; Namely&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Option is now a struct vs. class &lt;/li&gt;    &lt;li&gt;Added equality metrics &lt;/li&gt;    &lt;li&gt;Allowing implicit conversion T –&amp;gt; Option&amp;lt;T&amp;gt;&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;As usual, this is available in the latest version of RantPack: &lt;a title="http://code.msdn.microsoft.com/RantPack" href="http://code.msdn.microsoft.com/RantPack"&gt;http://code.msdn.microsoft.com/RantPack&lt;/a&gt;&lt;/p&gt; &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;pre class="code"&gt;[&lt;span style="color: #2b91af"&gt;Immutable&lt;/span&gt;]
[&lt;span style="color: #2b91af"&gt;Serializable&lt;/span&gt;]
[&lt;span style="color: #2b91af"&gt;SuppressMessage&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;Microsoft.Naming&amp;quot;&lt;/span&gt;, &lt;span style="color: #a31515"&gt;&amp;quot;CA1716&amp;quot;&lt;/span&gt;)]
&lt;span style="color: blue"&gt;public struct &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Option&lt;/span&gt;&amp;lt;T&amp;gt; : &lt;span style="color: #2b91af"&gt;IEquatable&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Option&lt;/span&gt;&amp;lt;T&amp;gt;&amp;gt;
{
    &lt;span style="color: blue"&gt;private readonly &lt;/span&gt;T m_value;
    &lt;span style="color: blue"&gt;private readonly bool &lt;/span&gt;m_hasValue;

    &lt;span style="color: blue"&gt;public static &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Option&lt;/span&gt;&amp;lt;T&amp;gt; Empty
    {
        &lt;span style="color: blue"&gt;get &lt;/span&gt;{ &lt;span style="color: blue"&gt;return new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Option&lt;/span&gt;&amp;lt;T&amp;gt;(); }
    }

    &lt;span style="color: blue"&gt;public bool &lt;/span&gt;HasValue
    {
        &lt;span style="color: blue"&gt;get &lt;/span&gt;{ &lt;span style="color: blue"&gt;return &lt;/span&gt;m_hasValue; }
    }

    [&lt;span style="color: #2b91af"&gt;DebuggerDisplay&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;m_value&amp;quot;&lt;/span&gt;)]
    &lt;span style="color: blue"&gt;public &lt;/span&gt;T Value
    {
        &lt;span style="color: blue"&gt;get
        &lt;/span&gt;{
            &lt;span style="color: blue"&gt;if &lt;/span&gt;(!HasValue)
            {
                &lt;span style="color: blue"&gt;throw new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;InvalidOperationException&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;Option does not have a value&amp;quot;&lt;/span&gt;);
            }

            &lt;span style="color: blue"&gt;return &lt;/span&gt;m_value;
        }
    }

    &lt;span style="color: blue"&gt;public &lt;/span&gt;T ValueOrDefault
    {
        &lt;span style="color: blue"&gt;get &lt;/span&gt;{ &lt;span style="color: blue"&gt;return &lt;/span&gt;m_hasValue ? m_value : &lt;span style="color: blue"&gt;default&lt;/span&gt;(T); }
    }

    &lt;span style="color: blue"&gt;public &lt;/span&gt;Option(T value)
    {
        m_hasValue = &lt;span style="color: blue"&gt;true&lt;/span&gt;;
        m_value = value;
    }

    &lt;span style="color: blue"&gt;#region &lt;/span&gt;Operators

    [&lt;span style="color: #2b91af"&gt;SuppressMessage&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;Microsoft.Usage&amp;quot;&lt;/span&gt;, &lt;span style="color: #a31515"&gt;&amp;quot;CA1801&amp;quot;&lt;/span&gt;)]
    [&lt;span style="color: #2b91af"&gt;SuppressMessage&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;Microsoft.Usage&amp;quot;&lt;/span&gt;, &lt;span style="color: #a31515"&gt;&amp;quot;CA2225&amp;quot;&lt;/span&gt;)]
    &lt;span style="color: blue"&gt;public static implicit operator &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Option&lt;/span&gt;&amp;lt;T&amp;gt;(&lt;span style="color: #2b91af"&gt;Option &lt;/span&gt;option)
    {
        &lt;span style="color: blue"&gt;return &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Option&lt;/span&gt;&amp;lt;T&amp;gt;.Empty;
    }

    [&lt;span style="color: #2b91af"&gt;SuppressMessage&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;Microsoft.Usage&amp;quot;&lt;/span&gt;, &lt;span style="color: #a31515"&gt;&amp;quot;CA1801&amp;quot;&lt;/span&gt;)]
    &lt;span style="color: blue"&gt;public static implicit operator &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Option&lt;/span&gt;&amp;lt;T&amp;gt;(T value)
    {
        &lt;span style="color: blue"&gt;return new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Option&lt;/span&gt;&amp;lt;T&amp;gt;(value);
    }

    &lt;span style="color: blue"&gt;public static bool operator &lt;/span&gt;==(&lt;span style="color: #2b91af"&gt;Option&lt;/span&gt;&amp;lt;T&amp;gt; left, &lt;span style="color: #2b91af"&gt;Option&lt;/span&gt;&amp;lt;T&amp;gt; right)
    {
        &lt;span style="color: blue"&gt;return &lt;/span&gt;left.Equals(right);
    }
    &lt;span style="color: blue"&gt;public static bool operator &lt;/span&gt;!=(&lt;span style="color: #2b91af"&gt;Option&lt;/span&gt;&amp;lt;T&amp;gt; left, &lt;span style="color: #2b91af"&gt;Option&lt;/span&gt;&amp;lt;T&amp;gt; right)
    {
        &lt;span style="color: blue"&gt;return &lt;/span&gt;!left.Equals(right);
    }

    &lt;span style="color: blue"&gt;#endregion

    #region &lt;/span&gt;IEquatable&amp;lt;T&amp;gt; Members

    &lt;span style="color: blue"&gt;public bool &lt;/span&gt;Equals(&lt;span style="color: #2b91af"&gt;Option&lt;/span&gt;&amp;lt;T&amp;gt; other)
    {
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(other.HasValue != &lt;span style="color: blue"&gt;this&lt;/span&gt;.HasValue)
        {
            &lt;span style="color: blue"&gt;return false&lt;/span&gt;;
        }

        &lt;span style="color: green"&gt;// Both don't have a value
        &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(!other.HasValue)
        {
            &lt;span style="color: blue"&gt;return true&lt;/span&gt;;
        }

        &lt;span style="color: blue"&gt;return &lt;/span&gt;&lt;span style="color: #2b91af"&gt;EqualityComparer&lt;/span&gt;&amp;lt;T&amp;gt;.Default.Equals(m_value, other.Value);
    }

    &lt;span style="color: blue"&gt;#endregion

    #region &lt;/span&gt;Overrides

    &lt;span style="color: blue"&gt;public override bool &lt;/span&gt;Equals(&lt;span style="color: blue"&gt;object &lt;/span&gt;obj)
    {
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(obj &lt;span style="color: blue"&gt;is &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Option&lt;/span&gt;&amp;lt;T&amp;gt;)
        {
            &lt;span style="color: blue"&gt;return &lt;/span&gt;Equals((&lt;span style="color: #2b91af"&gt;Option&lt;/span&gt;&amp;lt;T&amp;gt;)obj);
        }

        &lt;span style="color: blue"&gt;return false&lt;/span&gt;;
    }

    &lt;span style="color: blue"&gt;public override int &lt;/span&gt;GetHashCode()
    {
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(!HasValue)
        {
            &lt;span style="color: blue"&gt;return &lt;/span&gt;0;
        }

        &lt;span style="color: blue"&gt;return &lt;/span&gt;&lt;span style="color: #2b91af"&gt;EqualityComparer&lt;/span&gt;&amp;lt;T&amp;gt;.Default.GetHashCode(m_value);
    }

    &lt;span style="color: blue"&gt;#endregion
&lt;/span&gt;}

[&lt;span style="color: #2b91af"&gt;Immutable&lt;/span&gt;]
[&lt;span style="color: #2b91af"&gt;Serializable&lt;/span&gt;]
[&lt;span style="color: #2b91af"&gt;SuppressMessage&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;Microsoft.Naming&amp;quot;&lt;/span&gt;, &lt;span style="color: #a31515"&gt;&amp;quot;CA1716&amp;quot;&lt;/span&gt;)]
&lt;span style="color: blue"&gt;public sealed class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Option
&lt;/span&gt;{
    &lt;span style="color: blue"&gt;private static &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Option &lt;/span&gt;s_empty = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Option&lt;/span&gt;();

    &lt;span style="color: blue"&gt;private &lt;/span&gt;Option()
    {
    }

    &lt;span style="color: blue"&gt;public static &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Option&lt;/span&gt;&amp;lt;T&amp;gt; Create&amp;lt;T&amp;gt;(T value)
    {
        &lt;span style="color: blue"&gt;return new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Option&lt;/span&gt;&amp;lt;T&amp;gt;(value);
    }

    &lt;span style="color: blue"&gt;public static &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Option &lt;/span&gt;Empty
    {
        &lt;span style="color: blue"&gt;get &lt;/span&gt;{ &lt;span style="color: blue"&gt;return &lt;/span&gt;s_empty; }
    }
}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8987105" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jaredpar/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://blogs.msdn.com/jaredpar/archive/tags/F_2300_/default.aspx">F#</category><category domain="http://blogs.msdn.com/jaredpar/archive/tags/Functional/default.aspx">Functional</category></item><item><title>Unfold</title><link>http://blogs.msdn.com/jaredpar/archive/2008/10/07/unfold.aspx</link><pubDate>Tue, 07 Oct 2008 15:00:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8977472</guid><dc:creator>Jared Parsons</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/jaredpar/comments/8977472.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jaredpar/commentrss.aspx?PostID=8977472</wfw:commentRss><wfw:comment>http://blogs.msdn.com/jaredpar/rsscomments.aspx?PostID=8977472</wfw:comment><description>&lt;p&gt;F# has a handy method called Unfold.&amp;#160; Think of it as the logical opposite of an Aggregate function.&amp;#160; Aggregates take a sequence of elements and convert them to a single element.&amp;#160; An unfold method will take a single element and turn it into a (potentially infinite) sequence of elements.&amp;#160; &lt;/p&gt;  &lt;p&gt;The API is straight forward.&amp;#160; It takes two parameters&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;A seed/start value &lt;/li&gt;    &lt;li&gt;A function which takes in a seed value and returns either an Empty option to indicate the end of a sequence or a value of Type tuple with two arguments.&amp;#160; The first is the next element in the sequence and the second is the next seed value passed into the function.&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;This is a very powerful function which allows you to quickly build all sorts of interesting functions.&amp;#160; Lets look at a potential implementation of Enumerable.Range as an unfold expression.&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public static &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IEnumerable&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&amp;gt; Range(&lt;span style="color: blue"&gt;int &lt;/span&gt;start, &lt;span style="color: blue"&gt;int &lt;/span&gt;count)
{
    &lt;span style="color: blue"&gt;return &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Enumerable&lt;/span&gt;.Unfold(
        start,
        x =&amp;gt; x - start &amp;lt; count
            ? &lt;span style="color: #2b91af"&gt;Option&lt;/span&gt;.Create(&lt;span style="color: #2b91af"&gt;Tuple&lt;/span&gt;.Create(x, x + 1))
            : &lt;span style="color: #2b91af"&gt;Option&lt;/span&gt;.Empty);
}&lt;/pre&gt;

&lt;p&gt;Not as efficient as the framework version of Range but a good mental exercise to get your head around using Unfold.&amp;#160; Implementing this method in C# is fairly straight forward.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public static &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IEnumerable&lt;/span&gt;&amp;lt;TResult&amp;gt; Unfold&amp;lt;TSource, TResult&amp;gt;(
    TSource state, 
    &lt;span style="color: #2b91af"&gt;Func&lt;/span&gt;&amp;lt;TSource, &lt;span style="color: #2b91af"&gt;Option&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Tuple&lt;/span&gt;&amp;lt;TResult, TSource&amp;gt;&amp;gt;&amp;gt; func)
{
    &lt;span style="color: blue"&gt;if &lt;/span&gt;(func == &lt;span style="color: blue"&gt;null&lt;/span&gt;)
    {
        &lt;span style="color: blue"&gt;throw new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ArgumentNullException&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;func&amp;quot;&lt;/span&gt;);
    }

    &lt;span style="color: blue"&gt;return &lt;/span&gt;UnfoldHelper(state, func);
}

&lt;span style="color: blue"&gt;private static &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IEnumerable&lt;/span&gt;&amp;lt;TResult&amp;gt; UnfoldHelper&amp;lt;TSource, TResult&amp;gt;(
    TSource state, 
    &lt;span style="color: #2b91af"&gt;Func&lt;/span&gt;&amp;lt;TSource, &lt;span style="color: #2b91af"&gt;Option&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Tuple&lt;/span&gt;&amp;lt;TResult, TSource&amp;gt;&amp;gt;&amp;gt; func)
{
    &lt;span style="color: blue"&gt;do
    &lt;/span&gt;{
        &lt;span style="color: blue"&gt;var &lt;/span&gt;result = func(state);
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(!result.HasValue)
        {
            &lt;span style="color: blue"&gt;break&lt;/span&gt;;
        }

        &lt;span style="color: blue"&gt;yield return &lt;/span&gt;result.Value.First;
        state = result.Value.Second;
    } &lt;span style="color: blue"&gt;while &lt;/span&gt;(&lt;span style="color: blue"&gt;true&lt;/span&gt;);
}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8977472" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jaredpar/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://blogs.msdn.com/jaredpar/archive/tags/Patterns/default.aspx">Patterns</category><category domain="http://blogs.msdn.com/jaredpar/archive/tags/F_2300_/default.aspx">F#</category><category domain="http://blogs.msdn.com/jaredpar/archive/tags/Functional/default.aspx">Functional</category></item><item><title>Functional C#: Providing an Option</title><link>http://blogs.msdn.com/jaredpar/archive/2008/10/06/functional-c-providing-an-option.aspx</link><pubDate>Mon, 06 Oct 2008 15:00:16 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8977459</guid><dc:creator>Jared Parsons</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/jaredpar/comments/8977459.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jaredpar/commentrss.aspx?PostID=8977459</wfw:commentRss><wfw:comment>http://blogs.msdn.com/jaredpar/rsscomments.aspx?PostID=8977459</wfw:comment><description>&lt;p&gt;Sorry for the terrible pun in the title.&amp;#160; I wanted to blog about developing an F# style Option class for C# and I couldn't resist.&lt;/p&gt;  &lt;p&gt;The basics of an Option class are very straight forward.&amp;#160; It's a class that either has a value or doesn't.&amp;#160; It's almost like nullable but for every type and allows for nulls to be a valid value.&amp;#160; Here's a straight forward Option class I coded up. &lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public sealed class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Option&lt;/span&gt;&amp;lt;T&amp;gt; {
    &lt;span style="color: blue"&gt;private readonly &lt;/span&gt;T m_value;
    &lt;span style="color: blue"&gt;private readonly bool &lt;/span&gt;m_hasValue;
    &lt;span style="color: blue"&gt;public static &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Option&lt;/span&gt;&amp;lt;T&amp;gt; Empty {
        &lt;span style="color: blue"&gt;get &lt;/span&gt;{ &lt;span style="color: blue"&gt;return new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Option&lt;/span&gt;&amp;lt;T&amp;gt;(); }
    }
    &lt;span style="color: blue"&gt;public bool &lt;/span&gt;HasValue {
        &lt;span style="color: blue"&gt;get &lt;/span&gt;{ &lt;span style="color: blue"&gt;return &lt;/span&gt;m_hasValue; }
    }
    &lt;span style="color: blue"&gt;public &lt;/span&gt;T Value {
        &lt;span style="color: blue"&gt;get &lt;/span&gt;{
            &lt;span style="color: blue"&gt;if &lt;/span&gt;(!HasValue) {
                &lt;span style="color: blue"&gt;throw new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;InvalidOperationException&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;Option does not have a value&amp;quot;&lt;/span&gt;);
            }
            &lt;span style="color: blue"&gt;return &lt;/span&gt;m_value;
        }
    }
    &lt;span style="color: blue"&gt;public &lt;/span&gt;Option(T value) {
        m_hasValue = &lt;span style="color: blue"&gt;true&lt;/span&gt;;
        m_value = value;
    }
    &lt;span style="color: blue"&gt;private &lt;/span&gt;Option() {
        m_hasValue = &lt;span style="color: blue"&gt;false&lt;/span&gt;;
        m_value = &lt;span style="color: blue"&gt;default&lt;/span&gt;(T);
    }
}

&lt;span style="color: blue"&gt;public sealed class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Option &lt;/span&gt;{
    &lt;span style="color: blue"&gt;public static &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Option&lt;/span&gt;&amp;lt;T&amp;gt; Create&amp;lt;T&amp;gt;(T value) {
        &lt;span style="color: blue"&gt;return new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Option&lt;/span&gt;&amp;lt;T&amp;gt;(value);
    }
}&lt;/pre&gt;

&lt;p&gt;I modified a bit of terminology to be more consistent with other frameworks I use (Some/None -&amp;gt; Value,HasValue).&amp;#160; It's succinct, generic and has type inference friendly create functions.&amp;#160; Or does it?&amp;#160; &lt;/p&gt;

&lt;p&gt;Lets consider a function which has a return type of Option&amp;lt;int&amp;gt;.&amp;#160; Case 1 is Option with a value.&amp;#160; There is a type inference friendly Option.Create method which makes for a simple return expression.&amp;#160; No types needed.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #2b91af"&gt;Option&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&amp;gt; SomeMethod() {
    &lt;span style="color: blue"&gt;return &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Option&lt;/span&gt;.Create(42);
}&lt;/pre&gt;

&lt;p&gt;Now lets consider Case #2, None.&amp;#160; Here there is no handy inference method because what would we use for inference.&amp;#160; There is no variable with a Type to use so we are forced to be explicit about the type.&amp;#160; &lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #2b91af"&gt;Option&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&amp;gt; SomeMethod2() {
    &lt;span style="color: blue"&gt;return &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Option&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&amp;gt;.Empty;
}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;In this case we're not so bad off because we're dealing with a simple type.&amp;#160; But what about more complex types?&amp;#160; Consider for example a hypothetical Unfold method.&amp;#160; The termination expression would be Option&amp;lt;Tuple&amp;lt;int,string&amp;gt;&amp;gt;.Empty.&amp;#160; Anonymous types are even worse since they are unnamable and can not ever be the source of an option with this design.&amp;#160; This really pales in the usage category when compared with F#.&lt;/p&gt;

&lt;p&gt;Lets see if we can do better.&amp;#160; &lt;/p&gt;

&lt;p&gt;First we could consider a design where we have a static creation method Empty which takes variables that aren't ever used.&amp;#160; This will give us the benefit of type inference but at the expense of an API which is faulty to the core.&amp;#160; It forces the user to create parameters that aren't ever used.&amp;#160; Definitely not a good design.&lt;/p&gt;

&lt;p&gt;This leaves us with using a solution that doesn't involve variables of the necessary type.&amp;#160; This essentially forces us into a non-generic solution since we need variables for type inference.&amp;#160; This non-generic Option won't be compatible with our generic return type. But wait, what will the compiler do if two expressions have conflicting types?&amp;#160; Eventually it will attempt to perform a conversion.&amp;#160; So if we make our non-generic empty Option convertible to any generic empty Option we can use the compilers type safety to our advantage.&amp;#160; &lt;/p&gt;

&lt;p&gt;Definition a non-generic empty Option is straight forward.&amp;#160; &lt;br /&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public sealed class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Option &lt;/span&gt;{
    &lt;span style="color: blue"&gt;private static &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Option &lt;/span&gt;s_empty = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Option&lt;/span&gt;();
    &lt;span style="color: blue"&gt;private &lt;/span&gt;Option() {
    }
    &lt;span style="color: blue"&gt;public static &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Option &lt;/span&gt;Empty {
        &lt;span style="color: blue"&gt;get &lt;/span&gt;{ &lt;span style="color: blue"&gt;return &lt;/span&gt;s_empty; }
    }
    &lt;span style="color: blue"&gt;public static &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Option&lt;/span&gt;&amp;lt;T&amp;gt; Create&amp;lt;T&amp;gt;(T value) {
        &lt;span style="color: blue"&gt;return new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Option&lt;/span&gt;&amp;lt;T&amp;gt;(value);
    }
}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Using a private constructor allows us a high degree of confidence that any Option instance hanging around came from our Empty property and hence represents an empty option.&amp;#160; Now all we need to do is define a conversion on Option&amp;lt;T&amp;gt;.&amp;#160; Essentially we want to say that any non-generic Option is convertible to this instance.&amp;#160; Add the following to Option&amp;lt;T&amp;gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public static implicit operator &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Option&lt;/span&gt;&amp;lt;T&amp;gt;(&lt;span style="color: #2b91af"&gt;Option &lt;/span&gt;option) {
    &lt;span style="color: blue"&gt;return &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Option&lt;/span&gt;&amp;lt;T&amp;gt;.Empty;
}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Now, we can use an empty option in any generic scenario without having to specify ugly type parameters.&amp;#160; &lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #2b91af"&gt;Option&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&amp;gt; SomeMethod3() {
    &lt;span style="color: blue"&gt;return &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Option&lt;/span&gt;.Empty;
}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8977459" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jaredpar/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://blogs.msdn.com/jaredpar/archive/tags/Patterns/default.aspx">Patterns</category><category domain="http://blogs.msdn.com/jaredpar/archive/tags/F_2300_/default.aspx">F#</category><category domain="http://blogs.msdn.com/jaredpar/archive/tags/Functional/default.aspx">Functional</category></item><item><title>Euler #2</title><link>http://blogs.msdn.com/jaredpar/archive/2008/09/11/euler-2.aspx</link><pubDate>Thu, 11 Sep 2008 15:01:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8935849</guid><dc:creator>Jared Parsons</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/jaredpar/comments/8935849.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jaredpar/commentrss.aspx?PostID=8935849</wfw:commentRss><wfw:comment>http://blogs.msdn.com/jaredpar/rsscomments.aspx?PostID=8935849</wfw:comment><description>&lt;p&gt;Problem #2 came quite a bit faster. The yield syntax in F# is very similar to the C# iterator syntax and made translating this sample a breeze.&amp;#160; &lt;/p&gt;  &lt;p&gt;As a commenter posted, in problem #1, I would've been better served to use Seq.filter as opposed to Seq.choose for the purpose of filtering list.&amp;#160; I've applied that here.&amp;#160; One downfall of learning a new language is finding the right API.&amp;#160; I spent a bit of time reading through the Seq documentation looking for the equivalent of the Where extension method and could only find chose.&amp;#160; Lesson learned&lt;/p&gt;  &lt;p&gt;// Find the sum of all the even-valued terms in the sequence which do not exceed four million.    &lt;br /&gt;let problem2() =     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; let rec fib prev cur = seq {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; yield prev     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if cur &amp;lt; 4000000 then     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; yield! fib cur (prev+cur)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; fib 1 2     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; |&amp;gt; Seq.filter (fun x -&amp;gt; 0 = x % 2)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; |&amp;gt; Seq.sum&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8935849" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jaredpar/archive/tags/F_2300_/default.aspx">F#</category></item><item><title>Debugging F# list's</title><link>http://blogs.msdn.com/jaredpar/archive/2008/09/10/debugging-f-list-s.aspx</link><pubDate>Wed, 10 Sep 2008 15:00:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8938838</guid><dc:creator>Jared Parsons</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/jaredpar/comments/8938838.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jaredpar/commentrss.aspx?PostID=8938838</wfw:commentRss><wfw:comment>http://blogs.msdn.com/jaredpar/rsscomments.aspx?PostID=8938838</wfw:comment><description>&lt;p&gt;One of the lacking's of the latest F# CTP is debugger visualization support for the built-in list types.&amp;#160; Viewing a list in the debugger is decidedly tedious compared to the mscorlib collection classes.&amp;#160; Take the following quick code sample&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;module &lt;/span&gt;Main =
    &lt;span style="color: blue"&gt;do
        let &lt;/span&gt;l1 = [0..4]
        &lt;span style="color: blue"&gt;let &lt;/span&gt;l2 = List.map (&lt;span style="color: blue"&gt;fun &lt;/span&gt;a &lt;span style="color: blue"&gt;-&amp;gt; &lt;/span&gt;a.ToString()) l1
        &lt;span style="color: blue"&gt;let &lt;/span&gt;l3 = &lt;span style="color: blue"&gt;new &lt;/span&gt;System.Collections.Generic.List&amp;lt;int&amp;gt;()
        List.iter (&lt;span style="color: blue"&gt;fun &lt;/span&gt;i &lt;span style="color: blue"&gt;-&amp;gt; &lt;/span&gt;l3.Add(i)) l1
        MainModuleTemp.Main()   &lt;span style="color: green"&gt;// Breakpoint here&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Hit F5 in a F# console application and you'll get the following display. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jaredpar/WindowsLiveWriter/DebuggingFlists_129AA/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jaredpar/WindowsLiveWriter/DebuggingFlists_129AA/image_thumb.png" width="449" height="348" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Notice how the elements of the mscorlib List&amp;lt;&amp;gt; are immediately visible.&amp;#160; Getting to the data in a F# list is possible but it takes a lot more clicks than the mscorlib version.&amp;#160; This doesn't appear to be an oversight on the F# team either.&amp;#160; The expansion of mscorlib List&amp;lt;T&amp;gt; is controlled by the DebuggerTypeProxy attribute on the class definition.&amp;#160; If you fire up Reflector and dig into Fsharp.Core.dll and navigate to List&amp;lt;T&amp;gt; you'll notice it indeed has a DebuggerTypeProxy entry which is well formed and points to ListDebugView&amp;lt;T&amp;gt;.&amp;#160; &lt;/p&gt;

&lt;p&gt;ListDebugView&amp;lt;T&amp;gt; is essentially identical to the one for mscorlib List&amp;lt;T&amp;gt;.&amp;#160; So what gives?&amp;#160; The bug appears to be in the accessibility of the constructor.&amp;#160; Even though it's not explicit in the documentation of DebuggerTypeProxy, it appears that the target type must have a single argument constructor which is public.&amp;#160; The one for ListDebugView&amp;lt;T&amp;gt; is internal.&amp;#160; &lt;/p&gt;

&lt;p&gt;Normally this would be an easy enough problem to work around.&amp;#160; Add an assembly level attribute of type DebuggerTypeProxy pointing to List&amp;lt;T&amp;gt; and a modified version of ListDebugView.&amp;#160; Unfortunately that will not work in this case.&amp;#160; The debugger will prefer DebuggerTypeProxy instances added directly to a type over ones defined at an assembly level.&amp;#160; &lt;/p&gt;

&lt;p&gt;That is, except for two cases.&amp;#160; The debugger will give precedence to assembly level attributes which are defined in an assembly named autoexp.dll and placed in one of the following two locations&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Visualizers folder for the current user.&amp;#160; One my machine it is C:\Users\jaredp\Documents\Visual Studio 2008\Visualizers&lt;/li&gt;

  &lt;li&gt;Devenv global visualizer folder. C:\Program Files\Microsoft Visual Studio 9.0\Common7\Packages\Debugger\Visualizers\Original&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you navigate to either of these directories you will find both the default autoexp.dll and the source code used to compile it.&amp;#160; It's got quite a few entries you may want to add in a modified version.&amp;#160; Adding a new ListDebugView&amp;lt;T&amp;gt; here is possible but lets do it in F# instead.&lt;/p&gt;

&lt;p&gt;Since autoexp.dll has predecence all we need to do is build a new version which has the appropriate debugger attributes for the F# collections.&amp;#160; Fire up a new class library project named autoexp and have it output to either of the directories listed above.&amp;#160; Below is a sample definition to get you started.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;#light
open &lt;/span&gt;System.Diagnostics

&lt;span style="color: blue"&gt;module &lt;/span&gt;Main =
    &lt;span style="color: blue"&gt;type &lt;/span&gt;ListProxy&amp;lt;'a&amp;gt;(l:List&amp;lt;'a&amp;gt;) =
        [&amp;lt;DebuggerBrowsableAttribute(DebuggerBrowsableState.RootHidden)&amp;gt;]
        &lt;span style="color: blue"&gt;member &lt;/span&gt;this.Items = 
            Array.of_list l
            
    [&amp;lt;assembly: DebuggerDisplayAttribute(&lt;span style="color: maroon"&gt;&amp;quot;{Length}&amp;quot;&lt;/span&gt;, Target=typeof&amp;lt;List&amp;lt;int&amp;gt;&amp;gt;)&amp;gt;]
    [&amp;lt;assembly: DebuggerTypeProxyAttribute(typeof&amp;lt;ListProxy&amp;lt;int&amp;gt;&amp;gt;, Target=typeof&amp;lt;List&amp;lt;int&amp;gt;&amp;gt;)&amp;gt;]
    &lt;span style="color: blue"&gt;do 
        &lt;/span&gt;()
        &lt;/pre&gt;

&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;Don't be alarmed at the typeof&amp;lt;List&amp;lt;int&amp;gt;&amp;gt;.&amp;#160; The visualizer will work for any generic binding of List&amp;lt;T&amp;gt;.&amp;#160; In fact, reflector confirms that this attribute will be emitted with the type pointing at the unbound List&amp;lt;T&amp;gt; instead of List&amp;lt;int&amp;gt;. My lack of F# skills is failing me as to why.&amp;#160; I'd love to cry bug but I've found crying bug at a compiler is usually ... wrong.&amp;#160; &lt;/p&gt;

&lt;p&gt;In either case, once you build this and place in the appropriate folder, you should find the visualizations for List&amp;lt;&amp;gt; much more accessible.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jaredpar/WindowsLiveWriter/DebuggingFlists_129AA/image_4.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jaredpar/WindowsLiveWriter/DebuggingFlists_129AA/image_thumb_1.png" width="478" height="349" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8938838" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jaredpar/archive/tags/Debugging/default.aspx">Debugging</category><category domain="http://blogs.msdn.com/jaredpar/archive/tags/F_2300_/default.aspx">F#</category></item><item><title>Euler and F#</title><link>http://blogs.msdn.com/jaredpar/archive/2008/09/08/euler-and-f.aspx</link><pubDate>Mon, 08 Sep 2008 15:00:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8932002</guid><dc:creator>Jared Parsons</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/jaredpar/comments/8932002.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jaredpar/commentrss.aspx?PostID=8932002</wfw:commentRss><wfw:comment>http://blogs.msdn.com/jaredpar/rsscomments.aspx?PostID=8932002</wfw:comment><description>&lt;p&gt;I've been looking for some new problems to work on in F# to get more comfortable with the language.&amp;#160; I've been rather slack of late because of other projects but I had a little bit of time this week.&amp;#160; I decided it would be fun to join the crowd and play away at the problems on the &lt;a href="http://projecteuler.net/"&gt;project euler&lt;/a&gt; site.&amp;#160; That being said, answer #1.&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;module &lt;/span&gt;Euler =
    &lt;span style="color: blue"&gt;let &lt;/span&gt;problem1() =
        &lt;span style="color: blue"&gt;let &lt;/span&gt;test i = 
            &lt;span style="color: blue"&gt;match &lt;/span&gt;(0 = i % 3) || (0 = i % 5) &lt;span style="color: blue"&gt;with
                &lt;/span&gt;| &lt;span style="color: blue"&gt;true -&amp;gt; &lt;/span&gt;Some i
                | &lt;span style="color: blue"&gt;false -&amp;gt; &lt;/span&gt;None
        &lt;span style="color: blue"&gt;let &lt;/span&gt;targetSeq = Seq.choose test [0..999]
        Seq.sum targetSeq&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8932002" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jaredpar/archive/tags/F_2300_/default.aspx">F#</category></item><item><title>F# CTP First Impressions</title><link>http://blogs.msdn.com/jaredpar/archive/2008/09/03/f-ctp-first-impressions.aspx</link><pubDate>Wed, 03 Sep 2008 15:00:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8912436</guid><dc:creator>Jared Parsons</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/jaredpar/comments/8912436.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jaredpar/commentrss.aspx?PostID=8912436</wfw:commentRss><wfw:comment>http://blogs.msdn.com/jaredpar/rsscomments.aspx?PostID=8912436</wfw:comment><description>&lt;p&gt;I had a little bit of time this weekend to download the F# CTP.&amp;#160; The IDE portion of the CTP is a huge improvement over the previous CTP.&amp;#160; In particular the intellisense engine feels much more smooth, is available in new places and has much better results.&amp;#160; Project engine also has better integration.&amp;#160; Debugging support is much better.&amp;#160; &lt;/p&gt;  &lt;p&gt;Overall the IDE now really feels like a ... well IDE.&amp;#160; I felt like the previous CTP was forced into Visual Studio and had much more in common with the old C++ IDE than VB and C#.&amp;#160; This time around the IDE is just more smooth and more closely resembles other managed integrations.&amp;#160; Definately worth the upgrade.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8912436" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jaredpar/archive/tags/F_2300_/default.aspx">F#</category></item><item><title>F# CTP Released</title><link>http://blogs.msdn.com/jaredpar/archive/2008/08/29/f-ctp-released.aspx</link><pubDate>Fri, 29 Aug 2008 22:30:07 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8906447</guid><dc:creator>Jared Parsons</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/jaredpar/comments/8906447.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jaredpar/commentrss.aspx?PostID=8906447</wfw:commentRss><wfw:comment>http://blogs.msdn.com/jaredpar/rsscomments.aspx?PostID=8906447</wfw:comment><description>&lt;p&gt;A new version of the F# CTP was released today.&amp;nbsp; There are a lot of new improvements to the language and project system.&amp;nbsp; Check it out &lt;a href="http://blogs.msdn.com/dsyme/archive/2008/08/29/the-f-september-2008-ctp-is-now-available.aspx"&gt;here&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8906447" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jaredpar/archive/tags/F_2300_/default.aspx">F#</category></item></channel></rss>