Loading ...
Sorry, an error occurred while loading the content.

1405Re: Self-referencing array init

Expand Messages
  • Alan Post
    Oct 1, 2003
    • 0 Attachment
      In article <001b01c38805$f781f890$6f01a8c0@PWARP>, Nicolas Cannasse wrote:
      > [...]
      >> I don't like the following alternative:
      >>
      >> let arr = ref None
      >> in arr := Some (Array.init 10 ...)
      >
      > This is not an alternative, since arr will still be None until Array.init is
      > finished.

      My callbacks won't get called until after the array is initialized. I
      just want to be able to "tear off" arr into the closure context.

      > BTW, you can't have an array referencing itself because it's type would be :
      >
      > array array array array array .....
      >
      > (recursive type :)

      In the example I posted:

      let arr = Array.init 10
      (fun i -> Some (fun () -> if arr.(9-i) = None then
      prerr_endline "Ouch" ))

      the type of arr is just fine: it is an array of (unit -> unit)
      options.
    • Show all 11 messages in this topic