Discriminated Unions in C++

Earlier this week I started writing a function which needed to represent three states in the return value, two of which had an associated value.  In my mind I immediately came to the following solution type BuildAction = | Reset | LinkOneWithNext of Statement | LinkManyWithNext of Statement seq A discriminated union is perfectly suited…

4

Improving the display of F# seq<T>’s in the debugger

F#’s seq<T> expressions are a frustrating item to inspect at debug time.  A seq<T> value is a collection and when users inspect such a value at debug time they want to see the contents of the collection.  Instead they are often presented with a view resembling the following The reason this happens is a consequence…

0

Converting System.Func<T1..TN> to FSharpFunc<T,TResult>

Interop of delegate style types between F# and other .Net languages is a pain point that results from a fundamental difference in how delegates are represented in the F# language.  Typical .Net languages like C# see a delegate as taking 0 to N parameters and potentially returning a value.  F# represents all exposed delegates as…

3

Having fun with events in F#

Recently I ran into a situation where I needed to handle some events in F# in a special way.  In this particular case I wanted to be able to disable and re-enable my handler based on changes in the program.  Essentially the C# equivalent of continually adding and removing the handlers.  I started by using…

1

Making F# type inference friendly for C#

One of my current hobby projects, VsVim, requires me to make a lot of calls between F# and C# projects.  The core Vim engine is a pure F# solution based on Visual Studio’s new editor.  It additionally has a small hosting layer and a large test bed both written in C#.  When working with the…

5

Using F# Discriminated Unions in C# (Beta2)

While updating my VsVim editor extensions for Beta2 [1] I got hit by a change in the way F# exposed discriminated unions in metadata.  My extension consists of a core F# component with a corresponding set of unit tests written in C#.  It’s mostly API level testing and as such I use a lot of…

5

Vim Emulator Editor Extension Released

I just released version 0.5.0 of VsVim: a vim emulation editor extension for Visual Studio 2010 Beta1 written in F#.  This is a hobby project I’ve been working on for awhile now.  I expect to continue updating this release as time goes on as I use it on a daily basis and I’m interested in…

17

Mapping LINQ to F#

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!!!  The problem is I’m used to query comprehensions in LINQ terminology.  Select, Where and SelectMany are so ingrained into my programming they are…

2

Comparing Continuations in C# and F# Part 3: Double wrong

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.  Here’s the original sample: let FoldRight combine (sequence:seq<‘a>) acc = use e = sequence.GetEnumerator() let rec…

1

Comparing Continuations in C# and F# Part 2

In my last post I went over the differences between using a continuation in F# and C#.  As it turns out I was right about the limits and symptoms but wrong about the reason.  The F# code does indeed generate tail calls for part of the continuation.  However this is only a very small portion…

3