All declarations (or bindings as we tend to call them) are done via the let keyword.

let myArray = Array2D.create ...

Cheers,

Rob

By on 6/9/2009 1:32 AM ()

Maybe I wasn't very clear. I'll try to give an example of what I am trying to do...

type Node (id: int, enabled: bool) =
member v.Id = id
member v.Enabled = enabled

let arr = Array2D.create 10 10
arr.[0,0] = Node 0 false

I want to create a 10 by 10 matrix containing a bunch of nodes. The adding of the nodes is not done a binding time, but at run-time...

By on 6/9/2009 2:35 AM ()
1
2
let arr = Array2D.zeroCreate 10 10 
arr.[0,0] <- Node (0,false)
By on 6/9/2009 3:45 AM ()

omg, immutability is a bitch

By on 6/9/2009 4:39 AM ()

what? good thing?

I can understand some data needed to remain as is instantiated!

I'm new and don't know yet the diference between create and zeroCreate. (??)

Yesterday, I had no problem with initiating my array with numbers

cube.[i,j,k] <- i * 16 + j * 4 + k

i,j,k running through a loop.

the cube came out as I wanted using merely Array3D.create to create the cube.

By on 6/9/2009 5:07 AM ()

The zeroCreate function doesn't initialize the array, so you get values like 0 or null. So this is unsafe (you might get NullReferenceException at run-time if you forget to set a value). In most cases, I recommend you to avoid this function. You shoud use either create (sets the same value for all elements) or init (calls a function on each array cell).

Laurent

By on 6/9/2009 11:11 AM ()

I don't know, (yesterday afternoon (F# I do at home)) with create I couldn't figure out how to fill an array with knightjump reachable positions given the position to jump from (the issue at hand).

With zeroCreate the wanted array was easily produced, I reckon the type of the array with create is fixed with the last parameter, while with zeroCreate it is determined at runtime??. It simply works for me, I like C# for its typesafety, and currently haven't a clue how to fix types in F# (the F#-spec 1.9.6, is currently my main source of information, the helps me figuring out F#)

But a week into F# I already knightjump around my cube, yet to figure out how to implement the iteration I promised my friends to do in a functional manner.

By on 6/9/2009 10:20 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