From: Philippe Wang <lists@philippewang.info>
To: Yitzhak Mandelbaum <yitzhak@research.att.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] "opening" record types
Date: Wed, 22 Aug 2007 18:32:02 +0200 [thread overview]
Message-ID: <46CC6502.5090003@philippewang.info> (raw)
In-Reply-To: <67ECB685-E69A-43CA-867D-30B879DB0510@research.att.com>
Yet another suggestion :
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 ;;
module M :
sig
type t = { a : int; b : int; }
module N : sig type t = M.t = { a : int; b : int; } end
end
Then :
# include M.N;;
type t = M.t = { a : int; b : int; }
So that you can do :
# { a = 42 ; b = 23 } ;;
- : t = {a = 42; b = 23}
That way, when you change or add definitions, it's easy to spread
changes, and you export only what you want to export...
:-)
Cheers,
--
Philippe Wang
mail[at]philippewang.info
Yitzhak Mandelbaum wrote:
> Hi,
>
> I'm generally averse to opening modules, as I find it can make it hard
> to figure out where definitions are coming from. Instead, I prefer to
> bind only those pieces of the module that I need, and to do so
> explicitly. However, there is one instance in which I find myself
> with little choice: record types. In order to bind the
> field-constructors for a record, you need to copy the entire type from
> the module in which its declared. For example,
>
> module Foo =
> struct
> type t = {a: int; b:int}
> end
>
> without copying the type:
>
> let y = {Foo.a=3; Foo.b=4}
>
> with copying:
>
> type t = Foo.t = {a: int; b:int}
>
> let x = {a=3; b=4}
>
> While this is a nuisance to begin with, its even worse if the record
> type is subject to change -- each time it changes, you need to update
> every place where you copied the definition.
>
> Is there any way around this? That is, is there any way to use the
> field names of a record defined in another module without opening the
> whole module or copying the whole definition of the record.
>
> Cheers,
> Yitzhak
>
> --------------------------------------------------
> Yitzhak Mandelbaum
> AT&T Labs - Research
>
> http://www.research.att.com/~yitzhak
> <http://www.research.att.com/%7Eyitzhak>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
next prev parent reply other threads:[~2007-08-22 18:06 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 [this message]
2007-08-22 19:24 ` Jeremy Yallop
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=46CC6502.5090003@philippewang.info \
--to=lists@philippewang.info \
--cc=caml-list@yquem.inria.fr \
--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