* [Caml-list] module alias in a .mli file @ 2012-11-19 5:29 Francois Berenger 2012-11-19 6:02 ` Martin Jambon 2012-11-19 6:03 ` Wojciech Meyer 0 siblings, 2 replies; 10+ messages in thread From: Francois Berenger @ 2012-11-19 5:29 UTC (permalink / raw) To: caml-list Hello, Here is my stupid question of the day: can't I declare the following in a .mli file? module V3 = Vector3 Thanks a lot, F. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Caml-list] module alias in a .mli file 2012-11-19 5:29 [Caml-list] module alias in a .mli file Francois Berenger @ 2012-11-19 6:02 ` Martin Jambon 2012-11-19 6:36 ` Francois Berenger 2012-11-19 6:03 ` Wojciech Meyer 1 sibling, 1 reply; 10+ messages in thread From: Martin Jambon @ 2012-11-19 6:02 UTC (permalink / raw) To: Francois Berenger; +Cc: caml-list On Sun 18 Nov 2012 09:29:31 PM PST, Francois Berenger wrote: > Hello, > > Here is my stupid question of the day: > can't I declare the following in a .mli file? > > module V3 = Vector3 No, because "= Vector3" specifies an implementation. An mli file is a module interface, and module interfaces never contain implementations. However, you may want to do this, which does what it says: module V3 : module type of Vector3 ("language extension", since ocaml 3.12) Martin ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Caml-list] module alias in a .mli file 2012-11-19 6:02 ` Martin Jambon @ 2012-11-19 6:36 ` Francois Berenger 2012-11-19 10:35 ` David House 0 siblings, 1 reply; 10+ messages in thread From: Francois Berenger @ 2012-11-19 6:36 UTC (permalink / raw) Cc: caml-list On 11/19/2012 03:02 PM, Martin Jambon wrote: > On Sun 18 Nov 2012 09:29:31 PM PST, Francois Berenger wrote: >> Hello, >> >> Here is my stupid question of the day: >> can't I declare the following in a .mli file? >> >> module V3 = Vector3 > > No, because "= Vector3" specifies an implementation. > An mli file is a module interface, and module interfaces never contain > implementations. > > However, you may want to do this, which does what it says: > > module V3 : module type of Vector3 Thanks a lot! That's exactly what I needed. :) ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Caml-list] module alias in a .mli file 2012-11-19 6:36 ` Francois Berenger @ 2012-11-19 10:35 ` David House 2012-11-19 12:44 ` Paolo Donadeo 0 siblings, 1 reply; 10+ messages in thread From: David House @ 2012-11-19 10:35 UTC (permalink / raw) To: Francois Berenger; +Cc: caml-list Annoyingly though, there is no way to create a module alias in an mli. If, in an ml file, you have to refer often to Some_very_long_module_name, it can quite convenient to define an alias by doing "module Mod = Some_very_long_module_name" (or, locally, "let module Mod = Some_very_long_module_name in"). But there is no way of doing this in an mli: you have to use the long name every time. This is especially annoying if you have some big type that you want to expose in the mli. You really just want to copy-paste out of the ml file and stick it into the mli, but then you have to expand all the module aliases. (It's just a couple of goes with M-%, but still...) On Mon, Nov 19, 2012 at 6:36 AM, Francois Berenger <berenger@riken.jp> wrote: > On 11/19/2012 03:02 PM, Martin Jambon wrote: >> >> On Sun 18 Nov 2012 09:29:31 PM PST, Francois Berenger wrote: >>> >>> Hello, >>> >>> Here is my stupid question of the day: >>> can't I declare the following in a .mli file? >>> >>> module V3 = Vector3 >> >> >> No, because "= Vector3" specifies an implementation. >> An mli file is a module interface, and module interfaces never contain >> implementations. >> >> However, you may want to do this, which does what it says: >> >> module V3 : module type of Vector3 > > > Thanks a lot! That's exactly what I needed. :) > > > > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Caml-list] module alias in a .mli file 2012-11-19 10:35 ` David House @ 2012-11-19 12:44 ` Paolo Donadeo 2012-11-19 15:46 ` Tiphaine Turpin 0 siblings, 1 reply; 10+ messages in thread From: Paolo Donadeo @ 2012-11-19 12:44 UTC (permalink / raw) To: OCaml mailing list [-- Attachment #1: Type: text/plain, Size: 2051 bytes --] Actually this is not true, Martin explained how. :-) -- Paolo Sent by Gmail from Android Il giorno 19/nov/2012 11:35, "David House" <dhouse@janestreet.com> ha scritto: > Annoyingly though, there is no way to create a module alias in an mli. > > If, in an ml file, you have to refer often to > Some_very_long_module_name, it can quite convenient to define an alias > by doing "module Mod = Some_very_long_module_name" (or, locally, "let > module Mod = Some_very_long_module_name in"). But there is no way of > doing this in an mli: you have to use the long name every time. > > This is especially annoying if you have some big type that you want to > expose in the mli. You really just want to copy-paste out of the ml > file and stick it into the mli, but then you have to expand all the > module aliases. (It's just a couple of goes with M-%, but still...) > > On Mon, Nov 19, 2012 at 6:36 AM, Francois Berenger <berenger@riken.jp> > wrote: > > On 11/19/2012 03:02 PM, Martin Jambon wrote: > >> > >> On Sun 18 Nov 2012 09:29:31 PM PST, Francois Berenger wrote: > >>> > >>> Hello, > >>> > >>> Here is my stupid question of the day: > >>> can't I declare the following in a .mli file? > >>> > >>> module V3 = Vector3 > >> > >> > >> No, because "= Vector3" specifies an implementation. > >> An mli file is a module interface, and module interfaces never contain > >> implementations. > >> > >> However, you may want to do this, which does what it says: > >> > >> module V3 : module type of Vector3 > > > > > > Thanks a lot! That's exactly what I needed. :) > > > > > > > > > > -- > > Caml-list mailing list. Subscription management and archives: > > https://sympa.inria.fr/sympa/arc/caml-list > > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > > Bug reports: http://caml.inria.fr/bin/caml-bugs > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > [-- Attachment #2: Type: text/html, Size: 3164 bytes --] ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Caml-list] module alias in a .mli file 2012-11-19 12:44 ` Paolo Donadeo @ 2012-11-19 15:46 ` Tiphaine Turpin 2012-11-19 14:51 ` David House 2012-11-20 1:38 ` Francois Berenger 0 siblings, 2 replies; 10+ messages in thread From: Tiphaine Turpin @ 2012-11-19 15:46 UTC (permalink / raw) To: caml-list [-- Attachment #1: Type: text/plain, Size: 2956 bytes --] In fact, the solution module V3 : module type of Vector3 does not work completely, because, the equality between Vector3 and V3 is lost, which poses problem with the types defined by Vector 3. What works is: include module type of struct module V3 = Vector3 end Here is a full example: module M : sig module Vector3 : sig type t end (* module V3 : module type of Vector3 *) include module type of struct module V3 = Vector3 end end = struct module Vector3 = struct type t end module V3 = Vector3 end open M let id (x : Vector3.t) : V3.t = x Regards, Tiphaine On 11/19/12 13:44, Paolo Donadeo wrote: > > Actually this is not true, Martin explained how. :-) > > > -- > Paolo > Sent by Gmail from Android > > Il giorno 19/nov/2012 11:35, "David House" <dhouse@janestreet.com > <mailto:dhouse@janestreet.com>> ha scritto: > > Annoyingly though, there is no way to create a module alias in an mli. > > If, in an ml file, you have to refer often to > Some_very_long_module_name, it can quite convenient to define an alias > by doing "module Mod = Some_very_long_module_name" (or, locally, "let > module Mod = Some_very_long_module_name in"). But there is no way of > doing this in an mli: you have to use the long name every time. > > This is especially annoying if you have some big type that you want to > expose in the mli. You really just want to copy-paste out of the ml > file and stick it into the mli, but then you have to expand all the > module aliases. (It's just a couple of goes with M-%, but still...) > > On Mon, Nov 19, 2012 at 6:36 AM, Francois Berenger > <berenger@riken.jp <mailto:berenger@riken.jp>> wrote: > > On 11/19/2012 03:02 PM, Martin Jambon wrote: > >> > >> On Sun 18 Nov 2012 09:29:31 PM PST, Francois Berenger wrote: > >>> > >>> Hello, > >>> > >>> Here is my stupid question of the day: > >>> can't I declare the following in a .mli file? > >>> > >>> module V3 = Vector3 > >> > >> > >> No, because "= Vector3" specifies an implementation. > >> An mli file is a module interface, and module interfaces never > contain > >> implementations. > >> > >> However, you may want to do this, which does what it says: > >> > >> module V3 : module type of Vector3 > > > > > > Thanks a lot! That's exactly what I needed. :) > > > > > > > > > > -- > > Caml-list mailing list. Subscription management and archives: > > https://sympa.inria.fr/sympa/arc/caml-list > > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > > Bug reports: http://caml.inria.fr/bin/caml-bugs > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > [-- Attachment #2: Type: text/html, Size: 5336 bytes --] ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Caml-list] module alias in a .mli file 2012-11-19 15:46 ` Tiphaine Turpin @ 2012-11-19 14:51 ` David House 2012-11-20 1:38 ` Francois Berenger 1 sibling, 0 replies; 10+ messages in thread From: David House @ 2012-11-19 14:51 UTC (permalink / raw) To: Tiphaine Turpin; +Cc: caml-list Very clever! I had always been doing the following to re-establish the type equality: module V3 : module type of Vector3 with type t = Vector3.t with type Submodule.t = Vector3.Submodule.t ... etc But again: this is not a true alias. It actually defines and exposes a V3 module as a submodule of your module. E.g. if you're talking about foo.mli then other people would be able to say Foo.V3. On Mon, Nov 19, 2012 at 3:46 PM, Tiphaine Turpin <Tiphaine.Turpin@free.fr> wrote: > In fact, the solution > > > module V3 : module type of Vector3 > > does not work completely, because, the equality between Vector3 and V3 is > lost, which poses problem with the types defined by Vector 3. What works is: > > include module type of struct module V3 = Vector3 end > > Here is a full example: > > module M : sig > > module Vector3 : sig type t end > (* module V3 : module type of Vector3 *) > include module type of struct module V3 = Vector3 end > > end = struct > > module Vector3 = struct type t end > module V3 = Vector3 > > end > > open M > let id (x : Vector3.t) : V3.t = x > > > Regards, > > Tiphaine > > > > On 11/19/12 13:44, Paolo Donadeo wrote: > > Actually this is not true, Martin explained how. :-) > > > -- > Paolo > Sent by Gmail from Android > > Il giorno 19/nov/2012 11:35, "David House" <dhouse@janestreet.com> ha > scritto: >> >> Annoyingly though, there is no way to create a module alias in an mli. >> >> If, in an ml file, you have to refer often to >> Some_very_long_module_name, it can quite convenient to define an alias >> by doing "module Mod = Some_very_long_module_name" (or, locally, "let >> module Mod = Some_very_long_module_name in"). But there is no way of >> doing this in an mli: you have to use the long name every time. >> >> This is especially annoying if you have some big type that you want to >> expose in the mli. You really just want to copy-paste out of the ml >> file and stick it into the mli, but then you have to expand all the >> module aliases. (It's just a couple of goes with M-%, but still...) >> >> On Mon, Nov 19, 2012 at 6:36 AM, Francois Berenger <berenger@riken.jp> >> wrote: >> > On 11/19/2012 03:02 PM, Martin Jambon wrote: >> >> >> >> On Sun 18 Nov 2012 09:29:31 PM PST, Francois Berenger wrote: >> >>> >> >>> Hello, >> >>> >> >>> Here is my stupid question of the day: >> >>> can't I declare the following in a .mli file? >> >>> >> >>> module V3 = Vector3 >> >> >> >> >> >> No, because "= Vector3" specifies an implementation. >> >> An mli file is a module interface, and module interfaces never contain >> >> implementations. >> >> >> >> However, you may want to do this, which does what it says: >> >> >> >> module V3 : module type of Vector3 >> > >> > >> > Thanks a lot! That's exactly what I needed. :) >> > >> > >> > >> > >> > -- >> > Caml-list mailing list. Subscription management and archives: >> > https://sympa.inria.fr/sympa/arc/caml-list >> > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners >> > Bug reports: http://caml.inria.fr/bin/caml-bugs >> >> -- >> Caml-list mailing list. Subscription management and archives: >> https://sympa.inria.fr/sympa/arc/caml-list >> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners >> Bug reports: http://caml.inria.fr/bin/caml-bugs > > ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Caml-list] module alias in a .mli file 2012-11-19 15:46 ` Tiphaine Turpin 2012-11-19 14:51 ` David House @ 2012-11-20 1:38 ` Francois Berenger 2012-11-20 1:57 ` Francois Berenger 1 sibling, 1 reply; 10+ messages in thread From: Francois Berenger @ 2012-11-20 1:38 UTC (permalink / raw) To: caml-list On 11/20/2012 12:46 AM, Tiphaine Turpin wrote: > In fact, the solution > > module V3 : module type of Vector3 > > does not work completely, because, the equality between Vector3 and V3 > is lost, which poses problem with the types defined by Vector 3. What > works is: > > include module type of struct module V3 = Vector3 end It's a little verbose but might be closer to what I was looking for. > Here is a full example: > > module M : sig > > module Vector3 : sig type t end > (* module V3 : module type of Vector3 *) > include module type of struct module V3 = Vector3 end > > end = struct > > module Vector3 = struct type t end > module V3 = Vector3 > > end > > open M > let id (x : Vector3.t) : V3.t = x > > > Regards, > > Tiphaine > > > On 11/19/12 13:44, Paolo Donadeo wrote: >> >> Actually this is not true, Martin explained how. :-) >> >> >> -- >> Paolo >> Sent by Gmail from Android >> >> Il giorno 19/nov/2012 11:35, "David House" <dhouse@janestreet.com >> <mailto:dhouse@janestreet.com>> ha scritto: >> >> Annoyingly though, there is no way to create a module alias in an mli. >> >> If, in an ml file, you have to refer often to >> Some_very_long_module_name, it can quite convenient to define an alias >> by doing "module Mod = Some_very_long_module_name" (or, locally, "let >> module Mod = Some_very_long_module_name in"). But there is no way of >> doing this in an mli: you have to use the long name every time. >> >> This is especially annoying if you have some big type that you want to >> expose in the mli. You really just want to copy-paste out of the ml >> file and stick it into the mli, but then you have to expand all the >> module aliases. (It's just a couple of goes with M-%, but still...) >> >> On Mon, Nov 19, 2012 at 6:36 AM, Francois Berenger >> <berenger@riken.jp <mailto:berenger@riken.jp>> wrote: >> > On 11/19/2012 03:02 PM, Martin Jambon wrote: >> >> >> >> On Sun 18 Nov 2012 09:29:31 PM PST, Francois Berenger wrote: >> >>> >> >>> Hello, >> >>> >> >>> Here is my stupid question of the day: >> >>> can't I declare the following in a .mli file? >> >>> >> >>> module V3 = Vector3 >> >> >> >> >> >> No, because "= Vector3" specifies an implementation. >> >> An mli file is a module interface, and module interfaces never >> contain >> >> implementations. >> >> >> >> However, you may want to do this, which does what it says: >> >> >> >> module V3 : module type of Vector3 >> > >> > >> > Thanks a lot! That's exactly what I needed. :) >> > >> > >> > >> > >> > -- >> > Caml-list mailing list. Subscription management and archives: >> > https://sympa.inria.fr/sympa/arc/caml-list >> > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners >> > Bug reports: http://caml.inria.fr/bin/caml-bugs >> >> -- >> Caml-list mailing list. Subscription management and archives: >> https://sympa.inria.fr/sympa/arc/caml-list >> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners >> Bug reports: http://caml.inria.fr/bin/caml-bugs >> > ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Caml-list] module alias in a .mli file 2012-11-20 1:38 ` Francois Berenger @ 2012-11-20 1:57 ` Francois Berenger 0 siblings, 0 replies; 10+ messages in thread From: Francois Berenger @ 2012-11-20 1:57 UTC (permalink / raw) To: caml-list On 11/20/2012 10:38 AM, Francois Berenger wrote: > On 11/20/2012 12:46 AM, Tiphaine Turpin wrote: >> In fact, the solution >> >> module V3 : module type of Vector3 >> >> does not work completely, because, the equality between Vector3 and V3 >> is lost, which poses problem with the types defined by Vector 3. What >> works is: >> >> include module type of struct module V3 = Vector3 end > > It's a little verbose but might be closer to what I was looking for. Indeed, now I can write (and compile) a .mli file with: --- include module type of struct module BA = Bigarray end include module type of struct module BA3 = Bigarray.Array3 end [...] mutable grid : (int, BA.int8_unsigned_elt, BA.c_layout) BA3.t [...] --- Which is more compact than what I had previously. Thanks! :) F. >> Here is a full example: >> >> module M : sig >> >> module Vector3 : sig type t end >> (* module V3 : module type of Vector3 *) >> include module type of struct module V3 = Vector3 end >> >> end = struct >> >> module Vector3 = struct type t end >> module V3 = Vector3 >> >> end >> >> open M >> let id (x : Vector3.t) : V3.t = x >> >> >> Regards, >> >> Tiphaine >> >> >> On 11/19/12 13:44, Paolo Donadeo wrote: >>> >>> Actually this is not true, Martin explained how. :-) >>> >>> >>> -- >>> Paolo >>> Sent by Gmail from Android >>> >>> Il giorno 19/nov/2012 11:35, "David House" <dhouse@janestreet.com >>> <mailto:dhouse@janestreet.com>> ha scritto: >>> >>> Annoyingly though, there is no way to create a module alias in an >>> mli. >>> >>> If, in an ml file, you have to refer often to >>> Some_very_long_module_name, it can quite convenient to define an >>> alias >>> by doing "module Mod = Some_very_long_module_name" (or, locally, >>> "let >>> module Mod = Some_very_long_module_name in"). But there is no way of >>> doing this in an mli: you have to use the long name every time. >>> >>> This is especially annoying if you have some big type that you >>> want to >>> expose in the mli. You really just want to copy-paste out of the ml >>> file and stick it into the mli, but then you have to expand all the >>> module aliases. (It's just a couple of goes with M-%, but still...) >>> >>> On Mon, Nov 19, 2012 at 6:36 AM, Francois Berenger >>> <berenger@riken.jp <mailto:berenger@riken.jp>> wrote: >>> > On 11/19/2012 03:02 PM, Martin Jambon wrote: >>> >> >>> >> On Sun 18 Nov 2012 09:29:31 PM PST, Francois Berenger wrote: >>> >>> >>> >>> Hello, >>> >>> >>> >>> Here is my stupid question of the day: >>> >>> can't I declare the following in a .mli file? >>> >>> >>> >>> module V3 = Vector3 >>> >> >>> >> >>> >> No, because "= Vector3" specifies an implementation. >>> >> An mli file is a module interface, and module interfaces never >>> contain >>> >> implementations. >>> >> >>> >> However, you may want to do this, which does what it says: >>> >> >>> >> module V3 : module type of Vector3 >>> > >>> > >>> > Thanks a lot! That's exactly what I needed. :) >>> > >>> > >>> > >>> > >>> > -- >>> > Caml-list mailing list. Subscription management and archives: >>> > https://sympa.inria.fr/sympa/arc/caml-list >>> > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners >>> > Bug reports: http://caml.inria.fr/bin/caml-bugs >>> >>> -- >>> Caml-list mailing list. Subscription management and archives: >>> https://sympa.inria.fr/sympa/arc/caml-list >>> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners >>> Bug reports: http://caml.inria.fr/bin/caml-bugs >>> >> > > ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Caml-list] module alias in a .mli file 2012-11-19 5:29 [Caml-list] module alias in a .mli file Francois Berenger 2012-11-19 6:02 ` Martin Jambon @ 2012-11-19 6:03 ` Wojciech Meyer 1 sibling, 0 replies; 10+ messages in thread From: Wojciech Meyer @ 2012-11-19 6:03 UTC (permalink / raw) To: Francois Berenger; +Cc: caml-list module V3 : module type of Vector3 Francois Berenger <berenger@riken.jp> writes: > Hello, > > Here is my stupid question of the day: > can't I declare the following in a .mli file? > > module V3 = Vector3 > > Thanks a lot, > F. -- Wojciech Meyer http://danmey.org ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2012-11-20 1:57 UTC | newest] Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2012-11-19 5:29 [Caml-list] module alias in a .mli file Francois Berenger 2012-11-19 6:02 ` Martin Jambon 2012-11-19 6:36 ` Francois Berenger 2012-11-19 10:35 ` David House 2012-11-19 12:44 ` Paolo Donadeo 2012-11-19 15:46 ` Tiphaine Turpin 2012-11-19 14:51 ` David House 2012-11-20 1:38 ` Francois Berenger 2012-11-20 1:57 ` Francois Berenger 2012-11-19 6:03 ` Wojciech Meyer
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox