2

In C# I'd write something like

MyType arr = new MyType[10];

to alloc arr as array which has 10 items of type MyType.

How to do the same in F# ??

let mutable arr = ?????????????
DinGODzilla
  • 1,611
  • 4
  • 21
  • 34
  • 2
    Do you really need an array? F# and functional languages tend to like linked lists, with lots of syntax support for them... – popester Oct 25 '09 at 01:28
  • 1
    There are still plenty of times when arrays are the right choice. – Brian Oct 25 '09 at 02:36

2 Answers2

4

To initialise the array to the default (e.g. null or zero), use Array.zeroCreate:

let arr : int array = Array.zeroCreate 10

To initialise with a value, use Array.init.

itowlson
  • 73,686
  • 17
  • 161
  • 157
  • 2
    Note also 'Array.create' and 'Array.init', see the docs: http://msdn.microsoft.com/en-us/library/ee370273(VS.100).aspx – Brian Oct 25 '09 at 02:38
2

You could conceivably be interested in this discussion although it is in an OCaml context.

Community
  • 1
  • 1
Pascal Cuoq
  • 79,187
  • 7
  • 161
  • 281