caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] First class modules aliases
@ 2014-02-14  7:23 Christophe Troestler
  2014-02-14  8:57 ` Alain Frisch
       [not found] ` <20140215.152342.1020588167010524975.Christophe.Troestler@umons.ac.be>
  0 siblings, 2 replies; 7+ messages in thread
From: Christophe Troestler @ 2014-02-14  7:23 UTC (permalink / raw)
  To: OCaml Mailing List

Hi,

I have encoutered several annoyances with module aliasing in the
context of first class modules.  For example, if I declare

    module type A = sig type t end
    type 'a a = (module A with type t = 'a)
    module type IA = A with type t = int
    type ia = (module IA)

then I expect the types “int a” and “ia” to be equivalent but this is
not the case:

    let f (a: int a) = (a : ia)

gives the error

    This expression has type int a = (module A with type t = int)
    but an expression was expected of type ia = (module IA)

That's unfortunate because one may want to use the shortcut “IA” to
constraint various module types and still expect to be able to use the
general functions for “int a” on those.

Another example is:

    module X = struct
      module type T = sig type s end
      type 'a t = (module T with type s = 'a)
      let id (x: int t) = x
    end
    
    let f (x: int X.t) = x
    
    module Y = struct
      include X
      let h x = f(id x)
    end

To make it work, I basically have to perform by hand the aliasing that
“include X” should make:

    module Y : sig type 'a t  val h : int t -> int t end = struct
      type 'a t = 'a X.t
      let h x = f(X.id x)
    end

This problem makes modularity more difficult.

Are the above problems that one has to learn to live with when using
first class modules or may we expect the type checker to be able to
cope with them in the future?

Best,
C.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-02-15 15:06 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-14  7:23 [Caml-list] First class modules aliases Christophe Troestler
2014-02-14  8:57 ` Alain Frisch
2014-02-14  9:08   ` Jacques Garrigue
2014-02-14  9:22     ` Alain Frisch
2014-02-14 23:23       ` Jacques Garrigue
2014-02-14  9:39   ` Alain Frisch
     [not found] ` <20140215.152342.1020588167010524975.Christophe.Troestler@umons.ac.be>
2014-02-15 15:05   ` [Caml-list] First class modules from C Alain Frisch

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).