Re: why is acc here unbound
| Newsgroups | gmane.comp.lang.ocaml.beginners |
|---|---|
| Message-ID | <CAOOOohRv8ps_d+sL+tMch7-UUFH0xiv79S5C4AO6wO99s+_dLg@mail.gmail.com> |
Hi Roelof, in your function length, acc is defined as an argument of the inner function length2, so it is only available in the body of length2. Your use of acc is outside of this scope, that's why OCaml complains here that acc in undefined: there is no value acc defined in the scope of the expression "acc 0 list2 list". HTH, ph. 2014-11-05 16:25 GMT+01:00 Roelof Wobben [email protected] [ocaml_beginners] <[email protected]>: > Hello, > > I have this : > > let length list = > let rec length2 list2 acc = > match list2 with > | [] -> acc > | x::xs -> length2 xs (acc + 1) > in acc 0 list2 list ;; > > But as soon as I copie it into the ocaml prompt I see a message that the > acc in the part in acc 0 list2 list is unbound. > > Roelof > > > > > > ------------------------------------ > Posted by: Roelof Wobben <[email protected]> > ------------------------------------ > > Archives up to December 31, 2011 are also downloadable at > http://www.connettivo.net/cntprojects/ocaml_beginners > The archives of the very official ocaml list (the seniors' one) can be > found at http://caml.inria.fr > Attachments are banned and you're asked to be polite, avoid flames etc. > ------------------------------------ > > Yahoo Groups Links > > > >