let v_memory v = match v with
| Vec (size, vec) ->
let memory_array = Array.create size W in
let index_array = Array.create size false in
let new_vec = fun i ->
if i >= 0 && i < size then
(
if index_array.(i) then
memory_array.(i)
else
let result = vec i in
let () = memory_array.(i) <- result in
let () = index_array.(i) <- true in
result
)
else raise (Invalid_argument "vector overflow.")
in
return_Vec (size, new_vec)
| _ -> v