Skip to content

Instantly share code, notes, and snippets.

@richlander
Created July 20, 2015 17:24
Show Gist options
  • Save richlander/5f40956d8ccffec8eb4d to your computer and use it in GitHub Desktop.
Save richlander/5f40956d8ccffec8eb4d to your computer and use it in GitHub Desktop.
Simplified mutable values
// old approach - need a `ref` value
let sumSquares n =
let total = ref 0
{ 1 .. n } |> Seq.iter (fun i ->
total := !total + i*i
)
!total
// new approach - `mutable` just works
let sumSquares' n =
let mutable total = 0
{ 1 .. n } |> Seq.iter (fun i ->
total <- total + i*i
)
total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment