Monday, November 7, 2011

i++ kind of functionality in F#

As F# is immutable language, we will not be able to use i++ kind of functionality directly. You will have to combine the "mutable" and "module" feature of F# to achieve the i++ kind of functionality. Below here is the simple demonstration of this;

module Foo
       let mutable m_field = 0
       let next () =
             m_field <- m_field + 1; m_field

Just use Foo.next () whereever you need i++ kind of functionality.

No comments:

Post a Comment