1403Re: "ocaml_beginners":: Self-referencing array init
- Oct 1, 2003Alan Post <apost@...> writes:
> ocaml 3.06you could look to :
> I'm sure there's a simple way to do this, but I just can't think of
> I want to do something like:
> let arr = Array.init 10 (...use arr...)
> In my case, I want to stick a bunch of objects in an array, and
> reference that array in one of their callbacks. A simplified (and
> less sensible) version would look something like:
> let arr = Array.init 10
> (fun i -> Some (fun () -> if arr.(9-i) = None then
> prerr_endline "Ouch" ))
and use one of the functions Pierre Weis defines there.
or make you own.
>Ocaml make a lot of statical check. So he forbid what you are trying
> 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
(the right-hand side of let rec must not be the result of the
evaluation of some function).
>I don't know what you are trying exactly, but why don't you create
> In the silly case above, there's a reasonable default value, but
> that's not the case in my actual (lablgtk2) program.
first your array, then iterate over it for creating your callback.
- << Previous post in topic Next post in topic >>