Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
"opening" record types
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-08-21 (13:18)
From: Yitzhak Mandelbaum <yitzhak@r...>
Subject: "opening" record types

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 =
   type t = {a: int; b:int}

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.


Yitzhak Mandelbaum
AT&T Labs - Research