Skip to content

Instantly share code, notes, and snippets.

@mwolicki
Last active September 14, 2017 11:58
Show Gist options
  • Save mwolicki/71eb5ebab3a591c1e8b5d1f0fb53cedd to your computer and use it in GitHub Desktop.
Save mwolicki/71eb5ebab3a591c1e8b5d1f0fb53cedd to your computer and use it in GitHub Desktop.
class MainClass {
static void Main () {
var text = "abcdef";
System.Console.WriteLine (text);
Mutate (text);
System.Console.WriteLine (text);
}
unsafe static void Mutate (string text) {
fixed (char* t = text)
for (int i = 0; i < text.Length; i++)
t[i] = 'z';
}
}
#nowarn "9"
let mutate (txt:string) : unit =
use ch = fixed txt
for i = 0 to txt.Length - 1 do
Microsoft.FSharp.NativeInterop.NativePtr.set ch i 'z'
let text = "abcd"
printfn "%s" text
mutate text
printfn "%s" text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment