--- In ocaml_beginners%40yahoogroups.com">ocaml_beginners
yahoogroups.com, Richard Jones <rich
...> wrote:
> > Now I wanted to try out his code, but I can't seem to grasp the Ocaml
> > module system. I think it is completely obvious, but I can't seem to
> > get it working.
> >
> Will's code is a functor, which is probably the hardest part
> of the module system to grasp.
Thank you, now I feel slightly less foolish.
> If you want to pick up modules in general, try:
> http://caml.inria.fr/pub/docs/manual-ocaml/manual004.html or
> http://www.ocaml-tutorial.org/the_structure_of_ocaml_programs
Thank you, I did find the reference in the manual, but I'll give it
another try. Now that I have some working code to experiment with I
hope it will be easier to study.
> OK back to Will's code though ... He issued a corrected version here:
> http://wmfarr.blogspot.com/2006/10/correction-to-automatic.html
>
> Paste his (corrected) code into a file called "diff.ml"
> (http://annexia.org/tmp/diff.ml) and compile it using:
>
> ocamlc -c diff.ml
>
> Note that this code, per se, doesn't do anything except define this
> strange functor thing (remember: the hardest part of the module system
> to understand). To get it to do something we need to write the main
> part of the program, so create another file called test_diff.ml
> (http://annexia.org/tmp/test_diff.ml) containing:
>
> open Diff.DFloat;;
>
> let () =
> print_diff stdout (sin (C 1.0));
> print_endline "";
> let d_sin = d sin in
> print_diff stdout (d_sin (C 1.0));
> print_endline ""
>
> Compile and link together:
>
> ocamlc -c test_diff.ml
> ocamlc -o test_diff diff.cmo test_diff.cmo
> ./test_diff
Thank you for the elaborate example. It works perfectly.
Cheers,
Anders
.