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

1407Re: "ocaml_beginners"::[] Self-referencing array init

Expand Messages
  • Martin Jambon
    Oct 1, 2003
      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))

      If you want to create a recursive data structure, you can't use function
      calls using the object you are creating as an argument.

      This is allowed:
      let rec list = 1 :: list (* :: is not a function *)

      type a = A of a
      let rec a = A a (* pointer to itself *)

      This not allowed:
      let rec x = x + 1 (* ( + ) is a function *)

      let rec l = (fun _ -> []) l

      let rec l = l (* one type constructor is required *)

      -- Martin
    • Show all 11 messages in this topic