25 people like it.

reference to array element

Nice thing you can do in F# that you can't do in C#, pulling a reference to an array element as a local var.

1: 
2: 
3: 
4: 
5: 
6: 
7: 
let byrefArrayElement() = 
  let arr = [| 1; 2; 3; |]; 
  let mutable x = &arr.[0]
  x <- 2 
  printfn "%A" arr 

byrefArrayElement()
val byrefArrayElement : unit -> unit

Full name: Script.byrefArrayElement
val arr : int []
val mutable x : byref<int>
val printfn : format:Printf.TextWriterFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
Raw view New version

More information

Link:http://fssnip.net/2G
Posted:6 years ago
Author:fholm
Tags: array