caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] type issues with modules
@ 2003-11-11  5:33 Chris GauthierDickey
  2003-11-11  8:21 ` Jacques Garrigue
  0 siblings, 1 reply; 6+ messages in thread
From: Chris GauthierDickey @ 2003-11-11  5:33 UTC (permalink / raw)
  To: caml-list

I have a weird issue, but I'm not sure if it's related to the type
system or what's really going on.  I've boiled the problem down to the
simple case below. I have 4 files, two that are interfaces for the modules.

file: mod1.mli
type t1 = T1
val v: t1

file mod1.ml
type t1 = T1
let v = Mod2.f2 ()

file mod2.mli
val f2: unit -> Mod1.t1

file mod2.ml
let f2 ()  = Mod1.T1


I compile the files as such:

ocamlc -g mod1.mli
ocamlc -g mod2.mli
ocamlc -g mod1.ml

at which point I get the error:
The implementation mod1.ml does not match the interface mod1.cmi:
Values do not match: val v : Mod1.t1 is not included in val v: t1

which seems a little odd since t1 is certainly contained in Mod1.t1. I
feel like the types at this point are known, defined in the interface
file and that we know that the types in the ml file belong to the same
module as the interface. Am I wrong?

If I had the type expressions and change mod1.ml to:
type t1 = T1
let v:(Mod1.t1)

and then mod1.mli to
type t1 = T1
let v:(Mod1.t1)

I get the error: Unbound type constructor Mod1.t1, which makes some
sense. But again I'd argue that at this point, we know the name of the
module, so Mod1.t1 is the same thing as t1.

Maybe I'm totally missing something obvious?

Thanks in advance,
Chris

P.S. I know I can move t1 into another module, but for software
engineering reasons, I don't want to do that.


-------------------
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] 6+ messages in thread

* Re: [Caml-list] type issues with modules
  2003-11-11  5:33 [Caml-list] type issues with modules Chris GauthierDickey
@ 2003-11-11  8:21 ` Jacques Garrigue
  2003-11-11 17:25   ` Damien
  0 siblings, 1 reply; 6+ messages in thread
From: Jacques Garrigue @ 2003-11-11  8:21 UTC (permalink / raw)
  To: chrisg; +Cc: caml-list

From: Chris GauthierDickey <chrisg@cs.uoregon.edu>

> I have a weird issue, but I'm not sure if it's related to the type
> system or what's really going on.  I've boiled the problem down to the
> simple case below. I have 4 files, two that are interfaces for the modules.
> 
> file: mod1.mli
> type t1 = T1
> val v: t1
> 
> file mod1.ml
> type t1 = T1
> let v = Mod2.f2 ()
> 
> file mod2.mli
> val f2: unit -> Mod1.t1
> 
> file mod2.ml
> let f2 ()  = Mod1.T1
> 
> 
> I compile the files as such:
> 
> ocamlc -g mod1.mli
> ocamlc -g mod2.mli
> ocamlc -g mod1.ml
> 
> at which point I get the error:
> The implementation mod1.ml does not match the interface mod1.cmi:
> Values do not match: val v : Mod1.t1 is not included in val v: t1

Explanation:
As specified in the reference manual, the combination of .ml and .mli
is expected to mean:
  module type Sig_mod1 = sig <mod1.mli> end
  module Struct_mod1 = struct <mod1.ml> end
  module Mod1 : Sig_mod1 = Struct_mod1
This means that during the typing of the contents of mod1.ml, the
compiler does not know yet that it is defining Mod1 (no recursion).
As a result, the t1 in mod1.ml and the Mod1.t1 in mod2.mli are not
known to represent the same type. Hence the error.

Moreover, the possibility of creating mutual dependencies between
modules by compiling a module against a .mli of another module
depending on the first one is not intentional, and should probably not
be relied upon.

> P.S. I know I can move t1 into another module, but for software
> engineering reasons, I don't want to do that.

I'm wondering what you mean by software engineering reasons.
That you want to keep types and values in the same module?
Unfortunately, this does not work well with the absence of recursion
between modules. Putting all types in a third module is indeed the
simplest solution.

Jacques Garrigue

-------------------
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] 6+ messages in thread

* Re: [Caml-list] type issues with modules
  2003-11-11  8:21 ` Jacques Garrigue
@ 2003-11-11 17:25   ` Damien
  2003-11-12  1:12     ` Jacques Garrigue
  0 siblings, 1 reply; 6+ messages in thread
From: Damien @ 2003-11-11 17:25 UTC (permalink / raw)
  To: caml-list

On Tue, 11 Nov 2003 17:21:47 +0900 Jacques Garrigue wrote:
> As specified in the reference manual, the combination of .ml and .mli
> is expected to mean:
>   module type Sig_mod1 = sig <mod1.mli> end
>   module Struct_mod1 = struct <mod1.ml> end
>   module Mod1 : Sig_mod1 = Struct_mod1

Let's be a bit fussy...
 
The manual says :
<<
	module Mod1: sig <mod1.mli> end = struct <mod1.ml> end
>>

Hopefully, because the first translation would export hidden parts of
Mod1 via Struct_mod1.

But I think that giving a name to the signature of Mod1 (Sig_mod1) could
be useful :

<<
	module type MOD1 : sig <mod1.mli> end
	module Mod1 : MOD1 = struct <mod1.ml> end
>>

Especially when hand-packing some modules : 
"ocamlc -pack" checks the packed cmo against an optional interface file,
but the latter is rather boring to write, since one has to copy&paste
the content of each packed interface.

If the module types were given a name, one could just write 
<<
	module Mod1: MOD1
	...
>>

damien

PS: I tried "module Mod1: Sig_mod1", of course it doesn't work :-(

-------------------
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] 6+ messages in thread

* Re: [Caml-list] type issues with modules
  2003-11-11 17:25   ` Damien
@ 2003-11-12  1:12     ` Jacques Garrigue
  2003-11-12 12:51       ` Remi Vanicat
  2003-11-13 21:31       ` Issac Trotts
  0 siblings, 2 replies; 6+ messages in thread
From: Jacques Garrigue @ 2003-11-12  1:12 UTC (permalink / raw)
  To: Damien.Pous; +Cc: caml-list

From: Damien <Damien.Pous@ens-lyon.fr>

> But I think that giving a name to the signature of Mod1 (Sig_mod1) could
> be useful :
> 
> <<
> 	module type MOD1 : sig <mod1.mli> end
> 	module Mod1 : MOD1 = struct <mod1.ml> end
> >>
> 
> Especially when hand-packing some modules : 
> "ocamlc -pack" checks the packed cmo against an optional interface file,
> but the latter is rather boring to write, since one has to copy&paste
> the content of each packed interface.

I have already suggested in the past

  module type Mod1 = sig <mod1.mli> end
  module Mod1 : Mod1 = struct <mod1.ml> end

since modules and module types have independent name spaces.
But it was not accepted.
Maybe if more people insist, it will be added some day...

      Jacques

-------------------
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] 6+ messages in thread

* Re: [Caml-list] type issues with modules
  2003-11-12  1:12     ` Jacques Garrigue
@ 2003-11-12 12:51       ` Remi Vanicat
  2003-11-13 21:31       ` Issac Trotts
  1 sibling, 0 replies; 6+ messages in thread
From: Remi Vanicat @ 2003-11-12 12:51 UTC (permalink / raw)
  To: caml-list

Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp> writes:

> From: Damien <Damien.Pous@ens-lyon.fr>
>
>> But I think that giving a name to the signature of Mod1 (Sig_mod1) could
>> be useful :
>> 
>> <<
>> 	module type MOD1 : sig <mod1.mli> end
>> 	module Mod1 : MOD1 = struct <mod1.ml> end
>> >>
>> 
>> Especially when hand-packing some modules : 
>> "ocamlc -pack" checks the packed cmo against an optional interface file,
>> but the latter is rather boring to write, since one has to copy&paste
>> the content of each packed interface.
>
> I have already suggested in the past
>
>   module type Mod1 = sig <mod1.mli> end
>   module Mod1 : Mod1 = struct <mod1.ml> end
>
> since modules and module types have independent name spaces.
> But it was not accepted.
> Maybe if more people insist, it will be added some day...

It would be interesting indeed.

-- 
Rémi Vanicat

-------------------
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] 6+ messages in thread

* Re: [Caml-list] type issues with modules
  2003-11-12  1:12     ` Jacques Garrigue
  2003-11-12 12:51       ` Remi Vanicat
@ 2003-11-13 21:31       ` Issac Trotts
  1 sibling, 0 replies; 6+ messages in thread
From: Issac Trotts @ 2003-11-13 21:31 UTC (permalink / raw)
  To: caml-list

On Wed, Nov 12, 2003 at 10:12:11AM +0900, Jacques Garrigue wrote:
> From: Damien <Damien.Pous@ens-lyon.fr>
> 
> > But I think that giving a name to the signature of Mod1 (Sig_mod1) could
> > be useful :
> > 
> > <<
> > 	module type MOD1 : sig <mod1.mli> end
> > 	module Mod1 : MOD1 = struct <mod1.ml> end
> > >>
> > 
> > Especially when hand-packing some modules : 
> > "ocamlc -pack" checks the packed cmo against an optional interface file,
> > but the latter is rather boring to write, since one has to copy&paste
> > the content of each packed interface.
> 
> I have already suggested in the past
> 
>   module type Mod1 = sig <mod1.mli> end
>   module Mod1 : Mod1 = struct <mod1.ml> end
> 
> since modules and module types have independent name spaces.
> But it was not accepted.
> Maybe if more people insist, it will be added some day...

I too would like to see this added.  Out of curiousity, why was it 
rejected?

-- 
Issac Trotts
Programmer
Center for Neuroscience
University of California, Davis 

-------------------
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] 6+ messages in thread

end of thread, other threads:[~2003-11-13 21:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-11  5:33 [Caml-list] type issues with modules Chris GauthierDickey
2003-11-11  8:21 ` Jacques Garrigue
2003-11-11 17:25   ` Damien
2003-11-12  1:12     ` Jacques Garrigue
2003-11-12 12:51       ` Remi Vanicat
2003-11-13 21:31       ` Issac Trotts

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).