Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Zheng Li <li@pps.jussieu.fr>
To: caml-list@inria.fr
Subject: Re: A confusing module question
Date: Sat, 12 Jan 2008 00:38:26 +0100	[thread overview]
Message-ID: <87ir202arx.fsf@pps.jussieu.fr> (raw)
In-Reply-To: <891bd3390801111105xb75df53id4358939e8b2b05c@mail.gmail.com>


"Yaron Minsky" <yminsky@gmail.com> writes:
> I've been programming in OCaml for along time, and I still don't have
> a really good mental model to understand when some module trick I try
> is going to work.  How do people think about things like this?

OCaml distinguish "type representation" from "type equation", you may
want to check the "module type" section of the manual for the
definitions.

Now consider the example:

module type S = sig
   type exposed_t = {foo : int}
   type t = exposed_t
end

We shouldn't expect type exposed_t and type t to be semantically
equivelent, as

module type S = sig
   type exposed_t = {foo : int}
   type t = {foo : int} (* both syntactically and semantically invalid *)
end

Notice the problem here: the constructors ("foo" here) of type
representations are _nominally_ and _exclusive_ bound, which leads to
the fact that any type equivelences can only be defined through type
equations. Though we can define as many type equivelences (anywhere) as
we want, you won't be able to define a single identical type
represetation. In other words, type representation is _principle_ and
type equation isn't. So we shouldn't expect them to be _exchangable_
just because of type arithmetic.

Back to the example, module type S requires a type representation
exposed_t and it's type equivelence t. If given

module M:S = struct
  type t = {foo : int}
  type exposed_t = t
end

The compiler will fail to find exposed_t has any kind of "representation"
and t is not a type equivelence of anyone. You can re-export exposed_t's
representation as 

module M:S = struct
  type t = {foo: int}
  type exposed_t = t = {foo: int}
end

HTH.

-- 
Zheng Li
http://www.pps.jussieu.fr/~li


  parent reply	other threads:[~2008-01-11 22:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-11 19:05 Yaron Minsky
2008-01-11 20:59 ` [Caml-list] " Jeremy Yallop
2008-01-11 23:38 ` Zheng Li [this message]
2008-01-14  9:02 ` Keiko Nakata

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ir202arx.fsf@pps.jussieu.fr \
    --to=li@pps.jussieu.fr \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox