How do I create an F# mutable option type?

f#, mutable, option-type, types

Solution

You need to state the type explicitly to avoid "the Value Restriction" (or see "Automatic Generalization" on msdn):

let x : Ref<int option> = ref None

x := Some 4

Problem

I need to create a mutable `option<T>` type in F#. I've tried writing ``` let x = ref None ``` and subsequently writing ``` x := Some(z) ``` but it doesn't work. Help!

Original source