The mutable variable 'i' is used in an invalid way.?

后端 未结 1 1683
我寻月下人不归
我寻月下人不归 2020-12-20 16:00

I am attempting to write some simple code in F#, and i get this error:

Error   1   The mutable variable \'i\' is used in an invalid way. Mutable variables ma         


        
相关标签:
1条回答
  • 2020-12-20 16:28

    You can't refer to mutables inside a closure, and that includes such constructs as seq{} and async{} blocks.

    You could write

    let printProcess = async {
            let i = ref 1
            while true do
                System.Console.WriteLine(!i)
                i := !i + 1
        }
    

    See this blog for some discussion.

    0 讨论(0)
提交回复
热议问题