Also note that you only encounter this problem when entering code in F # interacative in turn. If you enter the first line without providing type annotations, you will receive an error message:
> let x = ref None;;
However, if you enter more code that uses the cell ref x (for example, assigns a value to it), then F # will be able to infer the type from the later part of the code, so you win. There is no need for any annotations. For instance:
> let x = ref None x := Some(10);;
This will work fine because F # will infer the type x from the second line. This means that you probably don't need type annotations if you send code in F # interactively for testing in large portions (and in compiled F # code you will almost never encounter this problem).
source share