caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Module equivalence across definitions
@ 2001-10-13 18:07 Lauri Alanko
  2001-10-17  7:05 ` Tom Hirschowitz
  0 siblings, 1 reply; 2+ messages in thread
From: Lauri Alanko @ 2001-10-13 18:07 UTC (permalink / raw)
  To: caml-list

[Pardon for possible duplicates]

Hello. Given:


module type T = sig
  type t
end

module A : T = struct
  type t = A
end

module B(X:T) = struct
  type t = B
  let v = B
end

module type CT = sig
  val a : B(A).t
end

module C : CT = struct
  module Aalias = A
  module BA = B(Aalias)
  let a = BA.v
end


I get an error:


Signature mismatch:
Modules do not match:
  sig
    module Aalias : sig type t = A.t end
    module BA : sig type t = B(Aalias).t = B val v : t end
    val a : BA.t
  end
is not included in
  CT
Values do not match: val a : BA.t is not included in val a : B(A).t


But changing "module BA = B(Aalias)" to "module BA = B(A)" makes everything
work.

What gives? I'm used to seeing structural equivalence being used everywhere
in O'Caml's type system, but here simply renaming a module seems to give it
a distinct new identity. Is this a bug or a feature?


Lauri Alanko
la@iki.fi
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


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

* [Caml-list] Module equivalence across definitions
  2001-10-13 18:07 [Caml-list] Module equivalence across definitions Lauri Alanko
@ 2001-10-17  7:05 ` Tom Hirschowitz
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Hirschowitz @ 2001-10-17  7:05 UTC (permalink / raw)
  To: Lauri Alanko; +Cc: caml-list



Hi, 

I think it is more a question of datatypes than of 
applicative functors, in the sense that if you replace 
the module B with something like

module B(X:T) = struct
  type t = int
  let v = 2
end

then it works.

It's just because sum types are some kind of abstract 
types, the constructors interfacing them with the outer 
world. For instance :

# module A = struct type t = A end;;

# module B = struct type t = A end;;

# A.A = B.A;;
This expression has type A.t but is here used with type B.t

Do you agree?

Lauri Alanko writes:
 > [Pardon for possible duplicates]
 > 
 > Hello. Given:
 > 
 > 
 > module type T = sig
 >   type t
 > end
 > 
 > module A : T = struct
 >   type t = A
 > end
 > 
 > module B(X:T) = struct
 >   type t = B
 >   let v = B
 > end
 > 
 > module type CT = sig
 >   val a : B(A).t
 > end
 > 
 > module C : CT = struct
 >   module Aalias = A
 >   module BA = B(Aalias)
 >   let a = BA.v
 > end
 > 
 > 
 > I get an error:
 > 
 > 
 > Signature mismatch:
 > Modules do not match:
 >   sig
 >     module Aalias : sig type t = A.t end
 >     module BA : sig type t = B(Aalias).t = B val v : t end
 >     val a : BA.t
 >   end
 > is not included in
 >   CT
 > Values do not match: val a : BA.t is not included in val a : B(A).t
 > 
 > 
 > But changing "module BA = B(Aalias)" to "module BA = B(A)" makes everything
 > work.
 > 
 > What gives? I'm used to seeing structural equivalence being used everywhere
 > in O'Caml's type system, but here simply renaming a module seems to give it
 > a distinct new identity. Is this a bug or a feature?
 > 
 > 
 > Lauri Alanko
 > la@iki.fi
 > -------------------
 > Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
 > 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/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


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

end of thread, other threads:[~2001-10-17  7:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-13 18:07 [Caml-list] Module equivalence across definitions Lauri Alanko
2001-10-17  7:05 ` Tom Hirschowitz

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