Closed jstolarek closed 7 years ago
That's what a trace looks like after each of the updates:
Store [] [ (0, Array [ (0, VDouble 3.0),(1,VDouble 0.0)])
, (1, Array [ (0, VArrLoc (StoreLabel 0) 2)
, (1, VArrLoc (StoreLabel 0) 2)])] 2
Store [] [ (0, Array [ (0, VDouble 3.0),(1,VDouble 3.0)])
, (1, Array [ (0, VArrLoc (StoreLabel 0) 2)
, (1, VArrLoc (StoreLabel 0) 2)])] 2
Store [] [ (0, Array [ (0, VDouble 2.0),(1,VDouble 3.0)])
, (1, Array [ (0, VArrLoc (StoreLabel 0) 2)
, (1,VArrLoc (StoreLabel 0) 2)])] 2
Store [] [ (0, Array [(0, VDouble 2.0),(1,VDouble 5.0)]),
(1, Array [(0, VArrLoc (StoreLabel 0) 2)
,(1, VArrLoc (StoreLabel 0) 2)])] 2
When we create an array N
by N
we should allocate N
arrays, each containing N
elements and then create one more array with each cell pointing to one of arrays. What happens in our case is that we allocate only one array of length N
and then each cell in the array-of-arrays points to that single array.
I think this bug report is misnamed. The same thing would happen in OCaml, because the default initialization value of the outer array would be shared.
That's not exactly what I would expect but if you're saying this is correct behaviour I'll close as invalid.
$ ocaml
OCaml version 4.03.0
# Array.make;;
- : int -> 'a -> 'a array = <fun>
# let arr = Array.make 2 (Array.make 2 0.0);;
val arr : float array array = [|[|0.; 0.|]; [|0.; 0.|]|]
# Array.set (Array.get arr 1) 1 2.0
;;
- : unit = ()
# arr;;
- : float array array = [|[|0.; 2.|]; [|0.; 2.|]|]
I had no experience with arrays in OCaml, so that's not what I expected. My expectations we're based on behaviour of imperative languages like C.
If I say:
I get