Hi,

In the line

1
let eim = [| for i in 0..1 -> new Dictionary<int,string>() |];;

new Dictionary<int,string>() is executed twice: once for i = 0 and another one for i = 1.
So every element for eim has a different dictionary.

In

1
2
3
let tim = Array2.create 2 2 (new Dictionary<int,string>() );;

new Dictionary<int,string>() is executed once, and then passed as a parameter for Array2.create, which proceeds to fill the entire 2x2 array with this value.
Think of this as:

1
2
3
4
5
let tim = 
  let d = new Dictionary<int,string>() in
  Array2.create 2 2 d;;

You should use Array2.init instead:

1
2
3
let tim = Array2.init 2 2 (fun _ _ -> new Dictionary<int,string>() );;

Hope this helps,
Friendly,
Dmitry

By on 4/29/2008 6:33 PM ()

@Dmitry

Thanks, that did it. (there should be a warning not to use .create with mutable data : ) )

By on 4/30/2008 1:41 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper