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

Properly Incrementing an IntPtr

Just as native pointer types are moved around with pointer arithmetic in native code, it can also be useful to move IntPtr types around in managed code.  Say for instance there is an IntPtr available which points to a native array of Dog instances.  To access the values of that array individually requires pointer arithmetic…

7

Comparing Continuations in F# and C#

Lately I’ve been playing quite a bit with F#.  I have several hobby projects I’m working on that take up a bit of my time.  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: RantPack. Recently…

4

Dereference a double IntPtr

A common PInvoke question is how to deal with a double pointer.  More specifically, how can one dereference an IntPtr to another pointer without using unsafe code?  Dereferencing a double pointer is done the same way a dereference to any other structure is done: Marshal.PtrToStructure.  PtrToStructure is used to transform a native pointer, in the…

3

PInvoke and COM objects

I’ve occasionally found the need to mix COM interop and PInvoke.  For certain scenarios it’s just easier to code up a PInvoke declaration and function.  It’s perfectly legal to include COM objects in these scenarios provided the appropriate Marshal attributes are added to the signature. The easiest way to accomplish scenario is to have the…

4

Stop the Beeping!!!

Recently I was working on a PowerShell script which involved translating byte arrays into strings using the appropriate encoding.  Unfortunately I kept getting the wrong choice for encoding and printed out essentially random data to the console screen.  Unfortunately random data + windows console screens = beeps, beeps and lots more beeps.  What’s even worse…

2