Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Jeremy Yallop <jeremy.yallop@ed.ac.uk>
To: Philippe Wang <lists@philippewang.info>
Cc: Yitzhak Mandelbaum <yitzhak@research.att.com>, caml-list@yquem.inria.fr
Subject: Re: [Caml-list] "opening" record types
Date: Wed, 22 Aug 2007 20:24:34 +0100	[thread overview]
Message-ID: <46CC8D72.50205@ed.ac.uk> (raw)
In-Reply-To: <46CC6502.5090003@philippewang.info>

Philippe Wang wrote:
> Instead of :
> #  module M = struct type t = { a : int ; b : int } end ;;
> module M : sig type t = { a : int; b : int; } end
> 
> Write :
> #  module M = struct type t = { a : int ; b : int } module N = struct 
> type t = M.t = { a : int ; b : int } end end ;;

I don't think this code is quite what you intended.

   # ({a = 0 ; b = 0 } : M.t );;
   Characters 1-17:
      ({a = 0 ; b = 0 } : M.t );;
      ^^^^^^^^^^^^^^^^
   This expression has type t = M.t but is here used with type M.t

I like the idea, though.  You can avoid duplicating the type definition 
by writing the inner module first.

   module M =
   struct
     module N = struct type t = { a : int; b : int } end
     include N
   end

Then, as before:

    open M.N

    { a = 0; b = 0 }

> That way, when you change or add definitions, it's easy to spread 
> changes, and you export only what you want to export...

Yes.  Unforunately, the technique is only useful if you have control of 
the module that you want to import.

Jeremy.


      reply	other threads:[~2007-08-22 19:24 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-21 13:18 Yitzhak Mandelbaum
2007-08-21 13:34 ` [Caml-list] " Olivier Andrieu
2007-08-21 22:19   ` Yaron Minsky
2007-08-21 13:42 ` Christophe TROESTLER
2007-08-21 13:55   ` Daniel de Rauglaudre
2007-08-21 13:47 ` Virgile Prevosto
2007-08-22 16:32 ` Philippe Wang
2007-08-22 19:24   ` Jeremy Yallop [this message]

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=46CC8D72.50205@ed.ac.uk \
    --to=jeremy.yallop@ed.ac.uk \
    --cc=caml-list@yquem.inria.fr \
    --cc=lists@philippewang.info \
    --cc=yitzhak@research.att.com \
    /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