* [Caml-list] Legality of using module types from .mli in .ml
@ 2003-01-14 19:14 Thorsten Ohl
2003-01-15 16:28 ` [Caml-list] " Julien Signoles
0 siblings, 1 reply; 5+ messages in thread
From: Thorsten Ohl @ 2003-01-14 19:14 UTC (permalink / raw)
To: caml-list; +Cc: Julien.Signoles
I'm often referring to module types defined in an interface file in
order to reduce redundancy. For example
$ cat a.mli
module type T = sig val n : int end
module M : T
$ cat a.ml
module type T = A.T
module M : T = struct let n = 42 end
where T can be rather long. Is this legal? The manual says in
section 6.12
A compilation unit behaves roughly as the module definition
module unit-name : sig unit-interface end = struct unit-implementation end
and refrains from defining `roughly' :-). I came up with conflicting
evidence:
O'Caml accepts it
$ ocamlopt a.mli a.ml
However, it is not equivalent to
module B :
sig
module type T = sig val n : int end
end =
struct
module type T = B.T
module M = struct let n = 42 end
end
which is obviously rejected by O'Caml, since B.T is not bound. The
pair (a.mli, a.ml) more closely resembles
module Aux_C =
struct
module type T = sig val n : int end
end
module type C =
sig
module type T = Aux_C.T
module M : T
end
module C : C =
struct
module type T = Aux_C.T
module M = struct let n = 42 end
end
without binding Aux.T. My question is now: is the pair (a.mli, a.ml)
intentionally legal or do I need to expand the reference A.T, as in
$ cat pedantic_a.mli
module type T = sig val n : int end
module M : T
$ cat pedantic_a.ml
module type T = sig val n : int end
module M : T = struct let n = 42 end
because I've have taken advantage of a bug in the compiler.
The reason I'm asking this, is that my shorthand [as in (a.mli, aml)]
breaks Julien Signoles' defunctorizer.
Cheers,
-Thorsten
--
Thorsten Ohl, Physics Dept., Wuerzburg Univ. -- ohl@physik.uni-wuerzburg.de
http://theorie.physik.uni-wuerzburg.de/~ohl/ [<=== PGP public key here]
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Caml-list] Re: Legality of using module types from .mli in .ml
2003-01-14 19:14 [Caml-list] Legality of using module types from .mli in .ml Thorsten Ohl
@ 2003-01-15 16:28 ` Julien Signoles
2003-01-15 16:59 ` Thorsten Ohl
0 siblings, 1 reply; 5+ messages in thread
From: Julien Signoles @ 2003-01-15 16:28 UTC (permalink / raw)
To: ohl; +Cc: caml-list
Thorsten Ohl wrote:
>
> I'm often referring to module types defined in an interface file in
> order to reduce redundancy. For example
>
> $ cat a.mli
> module type T = sig val n : int end
> module M : T
>
> $ cat a.ml
> module type T = A.T
> module M : T = struct let n = 42 end
>
> where T can be rather long. Is this legal?
For me, your module type declaration should be illegal in a.ml. But the
ocaml compiler accepts it...
So, is it an ocaml bug ? Orelse what is the exact semantic of (.mli,
.ml) ?
> The reason I'm asking this, is that my shorthand [as in (a.mli, aml)]
> breaks Julien Signoles' defunctorizer.
The previous example doesn't break my defunctorizer :
$ ocamldefun --version
1.02
$ ocamldefun a.mli a.ml
$ cat a.ml
module type T = A.T
module M = struct let n = 42 end
That's ok (normal because a.mli is still in the ocamldefun environment
when a.ml is defunctorized)...
Can you report me your example breaking my defunctorizer ?
Cheers,
Julien Signoles.
--
mailto : Julien.Signoles@lri.fr ; http : www.lri.fr/~signoles
"In theory, practice and theory are the same,
but in practice they are different" (Larry McVoy)
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Caml-list] Re: Legality of using module types from .mli in .ml
2003-01-15 16:28 ` [Caml-list] " Julien Signoles
@ 2003-01-15 16:59 ` Thorsten Ohl
2003-01-15 17:37 ` Julien Signoles
0 siblings, 1 reply; 5+ messages in thread
From: Thorsten Ohl @ 2003-01-15 16:59 UTC (permalink / raw)
To: Julien Signoles; +Cc: caml-list
Julien Signoles <Julien.Signoles@lri.fr> writes:
> The previous example doesn't break my defunctorizer :
>
> $ ocamldefun --version
> 1.02
> $ ocamldefun a.mli a.ml
> $ cat a.ml
> module type T = A.T
> module M = struct let n = 42 end
>
> That's ok (normal because a.mli is still in the ocamldefun environment
> when a.ml is defunctorized)...
The O'Caml compiler will later not be able to resolve A.T if you use
the `-d' option:
ohl@wptx47:~misc$ ocamldefun -v
1.02
ohl@wptx47:~misc$ cat a.mli
module type T = sig val n : int end
module M : T
ohl@wptx47:~misc$ cat a.ml
module type T = A.T
module M : T = struct let n = 42 end
ohl@wptx47:~misc$ ocamldefun -d defun a.mli a.ml
ohl@wptx47:~misc$ cd defun/
ohl@wptx47:~defun$ ls
a.cmd a.ml
ohl@wptx47:~defun$ cat a.ml
module type T = A.T
module M = struct let n = 42 end
ohl@wptx47:~defun$ ocamlopt a.ml
File "a.ml", line 1, characters 16-19:
Unbound module type A.T
I could ignore appendix B of the manual and create a a.cmi:
ohl@wptx47:~defun$ cp ../a.mli .
ohl@wptx47:~defun$ ocamlc a.mli
ohl@wptx47:~defun$ ocamlopt a.ml
but I'm not supposed to do that, am I?
BTW: given the (currently) uncertain semantics, I have started to
remove the construct from my applications.
--
Thorsten Ohl, Physics Dept., Wuerzburg Univ. -- ohl@physik.uni-wuerzburg.de
http://theorie.physik.uni-wuerzburg.de/~ohl/ [<=== PGP public key here]
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Caml-list] Re: Legality of using module types from .mli in .ml
2003-01-15 16:59 ` Thorsten Ohl
@ 2003-01-15 17:37 ` Julien Signoles
2003-01-15 21:57 ` David Brown
0 siblings, 1 reply; 5+ messages in thread
From: Julien Signoles @ 2003-01-15 17:37 UTC (permalink / raw)
To: ohl; +Cc: caml-list
> ohl@wptx47:~misc$ ocamldefun -v
> 1.02
> ohl@wptx47:~misc$ cat a.mli
> module type T = sig val n : int end
> module M : T
> ohl@wptx47:~misc$ cat a.ml
> module type T = A.T
> module M : T = struct let n = 42 end
> ohl@wptx47:~misc$ ocamldefun -d defun a.mli a.ml
> ohl@wptx47:~misc$ cd defun/
> ohl@wptx47:~defun$ ls
> a.cmd a.ml
> ohl@wptx47:~defun$ cat a.ml
> module type T = A.T
> module M = struct let n = 42 end
> ohl@wptx47:~defun$ ocamlopt a.ml
> File "a.ml", line 1, characters 16-19:
> Unbound module type A.T
>
> I could ignore appendix B of the manual and create a a.cmi:
>
> ohl@wptx47:~defun$ cp ../a.mli .
> ohl@wptx47:~defun$ ocamlc a.mli
> ohl@wptx47:~defun$ ocamlopt a.ml
>
> but I'm not supposed to do that, am I?
Effectively, you're not supposed to do that (except if you're sure that
the problem of the appendix B cannot be appear in your program).
Julien Signoles.
--
mailto : Julien.Signoles@lri.fr ; http : www.lri.fr/~signoles
"In theory, practice and theory are the same,
but in practice they are different" (Larry McVoy)
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] Re: Legality of using module types from .mli in .ml
2003-01-15 17:37 ` Julien Signoles
@ 2003-01-15 21:57 ` David Brown
0 siblings, 0 replies; 5+ messages in thread
From: David Brown @ 2003-01-15 21:57 UTC (permalink / raw)
To: Julien Signoles; +Cc: ohl, caml-list
On Wed, Jan 15, 2003 at 06:37:33PM +0100, Julien Signoles wrote:
> > ohl@wptx47:~misc$ ocamldefun -v
> > 1.02
> > ohl@wptx47:~misc$ cat a.mli
> > module type T = sig val n : int end
> > module M : T
> > ohl@wptx47:~misc$ cat a.ml
> > module type T = A.T
> > module M : T = struct let n = 42 end
> > ohl@wptx47:~misc$ ocamldefun -d defun a.mli a.ml
> > ohl@wptx47:~misc$ cd defun/
> > ohl@wptx47:~defun$ ls
> > a.cmd a.ml
> > ohl@wptx47:~defun$ cat a.ml
> > module type T = A.T
> > module M = struct let n = 42 end
> > ohl@wptx47:~defun$ ocamlopt a.ml
> > File "a.ml", line 1, characters 16-19:
> > Unbound module type A.T
> >
> > I could ignore appendix B of the manual and create a a.cmi:
> >
> > ohl@wptx47:~defun$ cp ../a.mli .
> > ohl@wptx47:~defun$ ocamlc a.mli
> > ohl@wptx47:~defun$ ocamlopt a.ml
Would it no work to
~misc$ ocamlc -c a.mli
~misc$ cd defun/
~misc$ ocamlopt -c -I .. a.ml
Dave Brown
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2003-01-15 21:58 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-14 19:14 [Caml-list] Legality of using module types from .mli in .ml Thorsten Ohl
2003-01-15 16:28 ` [Caml-list] " Julien Signoles
2003-01-15 16:59 ` Thorsten Ohl
2003-01-15 17:37 ` Julien Signoles
2003-01-15 21:57 ` David Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox