Imperative Programming(Chapter 4 of Programming F#)
The ref type, sometimes referred to as a ref cell, allows you to store mutable data on the heap, enabling you to bypass limitations with mutable values that are stored on the stack. To retrieve the value of a ref cell, use the ! symbolic operator and to set the value use the := operator.
1 > let planets = ref ["a"; "b"; "c"]
2 planets := !planets |> List.filter(fun p-> p <>"a");;
3
4 val planets : string list ref = {contents = ["b"; "c"];}
2 planets := !planets |> List.filter(fun p-> p <>"a");;
3
4 val planets : string list ref = {contents = ["b"; "c"];}