-1

I'm trying to create an array of strings so that I can modify the contents of the strings depending on the input parameter of a function. I've only started to use OCaml recently so I may be missing something simple here. Currently I have:

  let myArray = Array.make x "" in
    for i = 0 to Array.length myArray do
    myArray[i] = "SOME STRING HERE";
  done;

However when doing this, I get the following error when performing ocamlbuild

Error: This expression has type string array This is not a function; it cannot be applied.

Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
NiallMitch14
  • 1,198
  • 1
  • 12
  • 28

1 Answers1

1

Assignment to an array looks like this in OCaml:

myArray.(i) <- "SOME STRING HERE"

As an additional comment, your loop is accessing past the end of the array. The last element of an array is Array.length array - 1.

Jeffrey Scofield
  • 65,646
  • 2
  • 72
  • 108