List Info

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




"ocaml_beginners"::[] problem with recursive modules?
user name
2006-12-08 09:18:13

Hello,

Le jeu 07 déc 2006 23:41:12 CET,
&quot;drehman27" < drehman27%40yahoo.com">drehman27yahoo.com> a écrit :

> module Framework =
> functor (Alg : Algorithm) ->
>; struct
&gt; let f x = ...
> ...
> end

>; module FooAlgorithm : Algorithm =
> struct
&gt; ...
> Framework.f ... ------------> error
>; end
>
> module BenchmarkFoo = Framework(FooAlgorithm)
>

you may want to use recursive modules, an experimental feature of the
language described in section 7.9 of the manual. In your case, you
would define FooAlgorithm and BenchmarkFoo like this:

module rec FooAlgorithm: Algorithm =
struct
... BenchmarkFoo.f ...
end
and BenchmarkFoo = Framework(FooAlgorithm)

Note however that this is not the most stable feature of Ocaml, and
that there are some restrictions on the modules you can define that way.
--
E tutto per oggi, a la prossima volta.
Virgile

__._,_.___
.

__,_._,___
"ocaml_beginners"::[] problem with recursive modules?
user name
2006-12-08 12:30:04

I defined to following code, using recursive modules as you described,
but I got the same error:

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

module Framework =
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

module BenchmarkFoo = Framework(FooAlgorithm)

------------------------------------

File "test.ml", line 15, characters 19-55:
Unbound value BenchmarkFoo.print_benchmark_results
make[1]: *** [test.cmi] Error 2

--- In ocaml_beginners%40yahoogroups.com">ocaml_beginnersyahoogroups.com, Virgile Prevosto
<virgile.prevosto...> wrote:
&gt;
> Hello,
&gt;
> Le jeu 07 déc 2006 23:41:12 CET,
> "drehman27" <drehman27...> a écrit :
>
> > module Framework =
> > functor (Alg : Algorithm) ->
>; > struct
&gt; > let f x = ...
> > ...
> > end
>
> > module FooAlgorithm : Algorithm =
> > struct
&gt; > ...
> > Framework.f ... ------------> error
>; > end
> >
> > module BenchmarkFoo = Framework(FooAlgorithm)
> >
>
> you may want to use recursive modules, an experimental feature of the
> language described in section 7.9 of the manual. In your case, you
> would define FooAlgorithm and BenchmarkFoo like this:
>;
> module rec FooAlgorithm: Algorithm =
> struct
&gt; ... BenchmarkFoo.f ...
> end
> and BenchmarkFoo = Framework(FooAlgorithm)
>
> Note however that this is not the most stable feature of Ocaml, and
> that there are some restrictions on the modules you can define that way.
> --
> E tutto per oggi, a la prossima volta.
&gt; Virgile
&gt;

__._,_.___
.

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

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