Tuesday, June 14, 2011

Studying F# : Reference cell

Reference cell is a keyword for using immutable binding as mutable container approximately.

define reference cell

> let refCellInt = ref 10;;

val refCellInt : int ref = {contents = 10;}

change value in reference cell

> refCellInt := 20;;
val it : unit = ()
> System.Console.WriteLine(refCellInt.Value);;
20
val it : unit = ()

undefine reference cell

> let normallInt = !refCellInt;;

val normallInt : int = 20

No comments:

Post a Comment