Ray's playground

 

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"];}

 

posted on 2010-06-08 09:29  Ray Z  阅读(206)  评论(0编辑  收藏  举报

导航