It still doesn't work. Could you please fix my example so that it
compiles? Thanks
--- In ocaml_beginners%40yahoogroups.com">ocaml_beginners
yahoogroups.com, Virgile Prevosto
<virgile.prevosto
...> wrote:
>
> Le ven 08 déc 2006 15:52:50 CET,
> "drehman27" <drehman27
...> a écrit :
>
> > Ok. This is the program I wrote. But I am still having errors:
> > File "test.ml", line 21, characters 19-55:
> > Unbound value BenchmarkFoo.print_benchmark_results
> >
> > I am trying to build a small framework for testing different machine
> > learning algorithms, and I thought that using functors would be a nice
> > way to reuse code from the framework in each algorithm that I
> > implement. I didn't think it was that hard to use functors in OCaml.
>
> It is not that hard (well, until you begin to play with abstraction and
> type constraints). Basically, a functor is a function at the module
> level. You can also define functor types, as you've done below, but
> then you have to apply them to a module to obtain a module type.
>
> > module type FrameworkType =
> > functor (Alg : Algorithm) ->
> > sig
> > val print_benchmark_results : unit -> unit
> > end
>
> > module rec FooAlgorithm : Algorithm =
> > struct
> > let run_algorithm () = ()
> > let results () = BenchmarkFoo.print_benchmark_results ()
> > end
> > and BenchmarkFoo : FrameworkType = Framework(FooAlgorithm)
>
> Here, FrameworkType is a functor type, hence it has no component at all.
> Besides, this is not the type of Framework(FooAlgorithm), which would
> rather be FrameworkType(FooAlgorithm). It seems however that you can't
> use that as the type of a recursive module. Thus
> it seems that you should write something like
>
> module type FrameworkType =
> sig (* here we define a plain module type, not a functor type*)
> val print_benchmark_results : unit -> unit
> end
> ...
> module rec ...
> and BenchmarkFoo : FrameworkType = Framework(FooAlgorithm)
>
> In general, I'd say that it is sufficient to write the signature
> (module type) corresponding to the result of the functor application,
> rather than a whole functor type. Those are needed only if you want to
> define an higher-order functor.
>
> --
> E tutto per oggi, a la prossima volta.
> Virgile
>
.