Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create an F# mutable option type?

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!

like image 204
Dmitri Nesteruk Avatar asked Dec 22 '22 05:12

Dmitri Nesteruk


1 Answers

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
like image 161
Johan Kullbom Avatar answered Jan 05 '23 14:01

Johan Kullbom