Re: reverse a list. is this a good solution

"Sébastien Dailly [email protected] [ocaml_beginners]" <[email protected]>
Newsgroups gmane.comp.lang.ocaml.beginners
Message-ID <[email protected]>

Le 20/10/2014 19:49, Roelof Wobben [email protected] [ocaml_beginners] a 
écrit :
> Yes, I noticed and I try to understand the difference :
>
> I think you mean this function :
>
> let rec aux_rev l accum =
>
> DoI understand that this part in aux_rev[] takes care of a empty acc ?
> I find this solution a little bit confusing expecially the in part .
>

This is a very common pattern in the functionnal programming.

It's a good usage in OCaml to give the maximum of safety in the code, 
and expose only what is necessary.


The solution given by Chingfan gives one function, with the followin 
pattern :

 > let function1 arg1 =
 >  let function2 arg2 arg3 = …
 >  in function2 arg1 []

so in this case, the function2 is localy defined inside function1, and 
only function1 is visible from outside.

This allow to control how the data will be processed, and to be sure to 
get well-formatted arguments.

-- 
Sébastien
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.