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

1409Re: Self-referencing array init

Expand Messages
  • Alan Post
    Oct 1, 2003
      In article <Pine.LNX.4.40.0310011220400.1489-100000@pc-bioinfo1>, Martin Jambon wrote:
      > On Wed, 1 Oct 2003, Alan Post wrote:
      >> When I feed this to ocaml, it complains about arr being unbound.
      >> Doing a "let rec" yields the following amusing message:
      >> This kind of expression is not allowed as right-hand side of `let rec'
      > You simply can't destructure the value that you are creating.
      > For example this can't work:
      > let rec array = Array.init n (fun i -> array.(i))

      I guess the problem is that the compiler is not able to distinguish a
      safe use ("tearing off" the value for later use in a closure) from an
      unsafe use (using the value before it is initialized). So it
      disallows all but the simplest of uses.

      Sorry, it was just hard to wrap my brain around, given my day job as a
      C++ coder.
    • Show all 11 messages in this topic