开发者

Is it possible to declare mutable and immutable values/bindings simultaneously?

开发者 https://www.devze.com 2023-04-02 04:48 出处:网络
For example I want to declare let len, (*mutable*) i = if s.Length >= 2 && s.[0] = \'0\' && (s.[1] = \'x\' || s.[1] = \'X\') then

For example I want to declare

let len, (*mutable*) i =
            if s.Length >= 2 && s.[0] = '0' && (s.[1] = 'x' || s.[1] = 'X') then
                (s.Length - 2, 2)
            else (s.Length, 0)

constant binding len and mutable i, is it possible ?

Added : I will use references开发者_开发技巧 then

    let len, i =
        if s.Length >= 2 && s.[0] = '0' && (s.[1] = 'x' || s.[1] = 'X') then
            (s.Length - 2, ref 2)
        else (s.Length, ref 0)


No. mutable applies to the entire let binding. You'll have to do:

let len, i = ...
let mutable i = i
0

精彩评论

暂无评论...
验证码 换一张
取 消