* [Caml-list] Problems building a library, types go missing
@ 2013-07-28 0:13 Goswin von Brederlow
2013-07-29 11:03 ` Leo White
0 siblings, 1 reply; 3+ messages in thread
From: Goswin von Brederlow @ 2013-07-28 0:13 UTC (permalink / raw)
To: caml users
Hi,
I'm trying to build a library in one of 2 ways out of
seperate modules. All files are available via git from
https://github.com/mrvn/ocam-problems/tree/functor-in-lib-problem
git clone git@github.com:mrvn/ocam-problems.git
The first library works and uses these files:
internal/IntFoo.ml : implement module T
internal/IntWorks.ml : declare module type T_t and functor taking a T_t
lib/works.ml : library mapping internal to external modules
test/test1.ml : test functor with local module
test/test2.ml : test functor with libraries module
test/test3.ml : test privatness of internal module (MUST FAIL)
test/test4.ml : test3 with too many includes (SHOULD FAIL)
and the second fails and uses there files:
internal/IntFoo_t.ml : declare module type T_t
internal/IntFoo.ml : implement module T
internal/IntFails.ml : functor taking a IntFoo_t.T_t
lib/fails.ml : library mapping internal to external modules
test/test5.ml : test functor with local module (FAILS)
test/test6.ml : test functor with libraries module (FAILS)
test/test7.ml : test privatness of internal module (MUST FAIL)
test/test8.ml : test7 with too many includes (SHOULD FAIL)
Now my question is: Why does the Fails.Foo_t.T_t type get lost all of
a sudden unless I include the internal directory in the search path?
MfG
Goswin
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] Problems building a library, types go missing
2013-07-28 0:13 [Caml-list] Problems building a library, types go missing Goswin von Brederlow
@ 2013-07-29 11:03 ` Leo White
2013-08-01 15:00 ` Goswin von Brederlow
0 siblings, 1 reply; 3+ messages in thread
From: Leo White @ 2013-07-29 11:03 UTC (permalink / raw)
To: Goswin von Brederlow; +Cc: caml users
If you look at the interfaces for works.ml and fails.ml (using "ocamlc
-i"), you can see the problem:
works.ml:
module Foo : sig module T : sig type t = int val foo : t -> unit end end
module Functor :
sig
module type Foo_t = sig type t val foo : t -> unit end
module Make : functor (Foo : Foo_t) -> sig val do_foo : Foo.t -> unit end
end
fails.ml:
module Foo : sig module T : sig type t = int val foo : t -> unit end end
module Foo_t : sig module type T_t = sig type t val foo : t -> unit end end
module Functor :
sig
module Make :
functor (Foo : IntFoo_t.T_t) -> sig val do_foo : Foo.t -> unit end
end
As you can see the Fails.Functor.Make functor expects an argument with
module type IntFoo_t.T_t, while the Works.Functor.Make functor expects
an argument with module type Works.Functor.Foo_t.
Since you hide IntFoo_t when compiling your tests, the compiler cannot
find IntFoo_t.T_t and so it cannot check whether Fails.Functor.Make is
being applied correctly.
To fix this simply add a signature to Fails.Functor, or better yet add a
"fails.mli" to your project:
module Foo : sig module T : sig type t = int val foo : t -> unit end end
module Foo_t : sig module type T_t = sig type t val foo : t -> unit end end
module Functor :
sig
module Make :
functor (Foo : Foo_t.T_t) -> sig val do_foo : Foo.t -> unit end
end
Regards,
Leo
Goswin von Brederlow <goswin-v-b@web.de> writes:
> Hi,
>
> I'm trying to build a library in one of 2 ways out of
> seperate modules. All files are available via git from
>
> https://github.com/mrvn/ocam-problems/tree/functor-in-lib-problem
> git clone git@github.com:mrvn/ocam-problems.git
>
> The first library works and uses these files:
>
> internal/IntFoo.ml : implement module T
> internal/IntWorks.ml : declare module type T_t and functor taking a T_t
> lib/works.ml : library mapping internal to external modules
> test/test1.ml : test functor with local module
> test/test2.ml : test functor with libraries module
> test/test3.ml : test privatness of internal module (MUST FAIL)
> test/test4.ml : test3 with too many includes (SHOULD FAIL)
>
> and the second fails and uses there files:
>
> internal/IntFoo_t.ml : declare module type T_t
> internal/IntFoo.ml : implement module T
> internal/IntFails.ml : functor taking a IntFoo_t.T_t
> lib/fails.ml : library mapping internal to external modules
> test/test5.ml : test functor with local module (FAILS)
> test/test6.ml : test functor with libraries module (FAILS)
> test/test7.ml : test privatness of internal module (MUST FAIL)
> test/test8.ml : test7 with too many includes (SHOULD FAIL)
>
>
> Now my question is: Why does the Fails.Foo_t.T_t type get lost all of
> a sudden unless I include the internal directory in the search path?
>
> MfG
> Goswin
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] Problems building a library, types go missing
2013-07-29 11:03 ` Leo White
@ 2013-08-01 15:00 ` Goswin von Brederlow
0 siblings, 0 replies; 3+ messages in thread
From: Goswin von Brederlow @ 2013-08-01 15:00 UTC (permalink / raw)
To: caml-list
On Mon, Jul 29, 2013 at 12:03:33PM +0100, Leo White wrote:
>
> If you look at the interfaces for works.ml and fails.ml (using "ocamlc
> -i"), you can see the problem:
>
> works.ml:
>
> module Foo : sig module T : sig type t = int val foo : t -> unit end end
> module Functor :
> sig
> module type Foo_t = sig type t val foo : t -> unit end
> module Make : functor (Foo : Foo_t) -> sig val do_foo : Foo.t -> unit end
> end
>
> fails.ml:
>
> module Foo : sig module T : sig type t = int val foo : t -> unit end end
> module Foo_t : sig module type T_t = sig type t val foo : t -> unit end end
> module Functor :
> sig
> module Make :
> functor (Foo : IntFoo_t.T_t) -> sig val do_foo : Foo.t -> unit end
> end
>
> As you can see the Fails.Functor.Make functor expects an argument with
> module type IntFoo_t.T_t, while the Works.Functor.Make functor expects
> an argument with module type Works.Functor.Foo_t.
>
> Since you hide IntFoo_t when compiling your tests, the compiler cannot
> find IntFoo_t.T_t and so it cannot check whether Fails.Functor.Make is
> being applied correctly.
>
> To fix this simply add a signature to Fails.Functor, or better yet add a
> "fails.mli" to your project:
>
> module Foo : sig module T : sig type t = int val foo : t -> unit end end
> module Foo_t : sig module type T_t = sig type t val foo : t -> unit end end
> module Functor :
> sig
> module Make :
> functor (Foo : Foo_t.T_t) -> sig val do_foo : Foo.t -> unit end
> end
>
> Regards,
>
> Leo
Can I use some "with type" syntax instead? Something like
module Functor = (IntFails with type IntFoo_t.T_t = Foo_t.T_t)
I'm trying to keep the files short and few so I don't have to edit
multiple files every time I change something. At least till the API
stabilizes.
MfG
Goswin
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-08-01 15:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-28 0:13 [Caml-list] Problems building a library, types go missing Goswin von Brederlow
2013-07-29 11:03 ` Leo White
2013-08-01 15:00 ` Goswin von Brederlow
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox