about mutable in lambda

  • Thread starter Thread starter yoyo
  • Start date Start date
Y

yoyo

let mutable i = 0
let a = fun () -> i

The mutable variable 'i' is used in an invalid way. Mutable variables may
not be captured by closures. Consider eliminating this use of mutation or
using a heap-allocated mutable reference cell via 'ref' and '!'.


why "i" can not use here?
 
yoyo said:
let mutable i = 0
let a = fun () -> i

The mutable variable 'i' is used in an invalid way. Mutable variables may
not be captured by closures. Consider eliminating this use of mutation or
using a heap-allocated mutable reference cell via 'ref' and '!'.


why "i" can not use here?

This sounds like F# to me not C#.

Try asking this on an F# forum which I note you already have.
 
Back
Top