Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: Yet another question about the module system
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Xavier Leroy <Xavier.Leroy@i...>
Subject: Re: Yet another question about the module system

> Suppose i have 2 files:
> 
> A first one, specifying an interface for an abstract type Bar:
> 
> ****** bar.mli **********
> type t
> val x :t
> *************************
> 
> A second one, specifying a second abstract type built upon the first one
> using functor application
> 
> ****** foo.mli **********
> module type FOO = sig type t val y : t end
> module Make(B:Bar) : (FOO with type t = Bar.t)
> *************************
> 
> Trying to compile this separately:
> 
> 	> ocamlc -c bar.mli
> 	> ocamlc -c foo.mli
> 
> produces the following error message:
> 	> File "foo.mli", line 3, characters 14-17: Unbound module type Bar

Having a bar.cmi file around defines a module named "Bar", but not a
module type named "Bar".

You're confusing a module "value" (a module implementation, such as
Bar) with a module type (a module specification, such as the one
expected for the type of the module parameter B).

> So, it seems that the Bar interface is known when compiling Foo (i guess this
> goes trough the bar.cmi file).
> Why cannot it be used as a functor argument then ?

It can be used as a functor argument, as in

        module B = Foo.Make(Bar)

but not as the type of a functor parameter, as in your example.

- Xavier Leroy