Struct 如何使用F将值设置为结构的'Item'#

Struct 如何使用F将值设置为结构的'Item'#,struct,f#,set,Struct,F#,Set,如何将值设置为结构的项?我尝试了以下两种类型,但最终都出现了值必须是可变的错误 module Test1 = [<Struct>] type Test (array: float []) = member o.Item with get i = array.[i] and set i value = array.[i] <- value let test = Test [|0.0|] test.[0] <- 4.0 mo

如何将值设置为结构的
?我尝试了以下两种类型,但最终都出现了
值必须是可变的
错误

module Test1 =
  [<Struct>]
  type Test (array: float []) =
    member o.Item
      with get i = array.[i]
      and set i value = array.[i] <- value

  let test = Test [|0.0|]
  test.[0] <- 4.0

module Test2 =

  [<Struct>]
  type Test =
    val mutable array: float []
    new (array: float []) = { array = array }
    member o.Item
      with get i = o.array.[i]
      and set i value = o.array.[i] <- value

  let test = Test [|0.0|]
  test.[0] <- 4.0
模块测试1=
[]
型式试验(阵列:浮点[])=
成员o.项目
使用get i=数组。[i]
并设置i value=array。[i]请尝试替换:

 let test = Test [|0.0|]
与:

 let mutable test = Test [|0.0|]