0

如何设置Item结构的值?我尝试了以下两种类型,但都以value must be mutable错误告终。

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
4

1 回答 1

2

请尝试更换:

 let test = Test [|0.0|]

和:

 let mutable test = Test [|0.0|]
于 2013-04-18T08:04:48.007 回答