1407Re: "ocaml_beginners":: Self-referencing array init
- Oct 1, 2003On Wed, 1 Oct 2003, Alan Post wrote:
> When I feed this to ocaml, it complains about arr being unbound.You simply can't destructure the value that you are creating.
> Doing a "let rec" yields the following amusing message:
> This kind of expression is not allowed as right-hand side of `let rec'
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 *)
- << Previous post in topic Next post in topic >>