List Info

Thread: "ocaml_beginners"::[] Re: problem with recursive modules?




"ocaml_beginners"::[] Re: problem with recursive modules?
user name
2006-12-08 14:22:01

Le ven 08 déc 2006 14:04:17 CET,
&quot;drehman27" < drehman27%40yahoo.com">drehman27yahoo.com> a écrit :
> --- In ocaml_beginners%40yahoogroups.com">ocaml_beginnersyahoogroups.com, Virgile Prevosto
> <virgile.prevosto...> wrote:
&gt; > > module rec FooAlgorithm : Algorithm =
> > > struct
&gt; > > let run_algorithm () = ()
> > > let results () = BenchmarkFoo.print_benchmark_results ()
> > > end
> > >
> > > module BenchmarkFoo = Framework(FooAlgorithm)
> >
> > You have to tell ocaml that FooAlgorithm and BenchmarkFoo are in the
> > same recursive block, using the 'and' keyword (exactly like in
> >
> I tried with 'and' keyword but I get a syntax error!
&gt; I am using ocaml 3.0.9.2

I guess that in case of recursive modules, it is mandatory to supply
the type of each of the module involved (hence, ocaml expects a ':'
instead of '=' right after the module's name).
For instance, you could have

module type FrameworkType = sig ... end

and then

module rec ...
and BenchMarkFoo: FrameworkType = Framework(FooAlgorithm)

--
E tutto per oggi, a la prossima volta.
Virgile

__._,_.___
.

__,_._,___
"ocaml_beginners"::[] Re: problem with recursive modules?
user name
2006-12-08 15:52:50

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.

module type Algorithm =
sig
val run_algorithm : unit -> unit
end

module type FrameworkType =
functor (Alg : Algorithm) ->
sig
val print_benchmark_results : unit -> unit
end

module Framework : FrameworkType =
functor (Alg : Algorithm) ->
struct
let print_benchmark_results () = print_endline "Excelent!"
end

module rec FooAlgorithm : Algorithm =
struct
let run_algorithm () = ()
let results () = BenchmarkFoo.print_benchmark_results ()
end
and BenchmarkFoo : FrameworkType = Framework(FooAlgorithm)

__._,_.___
.

__,_._,___
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )