Monday, August 08, 2011

F# and the immediate window

(This post is inspired from this Stack Overflow question)

F# debugger integration is quite good, except for the immediate window. The immediate window requires C# style syntax, so calling F# functions is not intuitive. Below are recipes for the immediate window integrated into a console application. As always code can be found here:
// Learn how to use the immediate window for F#.
module Program=

    // To build, add  a reference to Microsoft.CSharp. This is required for dynamic support in
    // the debugger.
    let allowDynamicToWorkFromImmediateWindowByLoadingCSharpBinders = Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags.BinaryOperationLogical

    let plusOne = (+)1
    let xPlusOnes = [1;2;3] |> plusOne
    let main (args) = 
       printfn  "Try the following in the immediate window:
// plusOne 4

// Seq.Head xPlusOnes

// let xPlusTwos= xPlusOnes |> plusOne 
// Seq.Head xPlusTwos
var xPlusTwos = Microsoft.FSharp.Collections.SeqModule.Map(plusOne,xPlusOnes);

       let returnValue = 1 

No comments: