Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Side effect
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Florian Hars <florian@h...>
Subject: Re: [Caml-list] Side effect
Nicolas FRANCOIS (AKA El Bofo) wrote:
> So matrix m was modified. But I work on a copy of m in
> Pivot_Z.pivot_ligne_sans_echange. What's the problem doc ?

Yes, m' is a copy of m, but the elements of m are arrays, so the copy m' 
  contains references to the same arrays that m contains, so m.(i).(j) 
is the same cell as m'.(i).(j). See:

         Objective Caml version 3.04

# let m = [|[|1;2|];[|3;4|]|];;
val m : int array array = [|[|1; 2|]; [|3; 4|]|]
# let m' = Array.copy m;;
val m' : int array array = [|[|1; 2|]; [|3; 4|]|]
# m'.(1).(1)<-99;;
- : unit = ()
# m';;
- : int array array = [|[|1; 2|]; [|3; 99|]|]
# m;;
- : int array array = [|[|1; 2|]; [|3; 99|]|]
# m'.(1) <- [|0;0|];;
- : unit = ()
# m'
   ;;
- : int array array = [|[|1; 2|]; [|0; 0|]|]
# m;;
- : int array array = [|[|1; 2|]; [|3; 99|]|]
#

Yours, Florian.

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners