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
[Caml-list] Pseudo-extensible records
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-10-15 (11:34)
From: Martin Jambon <martin_jambon@e...>
Subject: [Caml-list] Pseudo-extensible records

I was thinking of some way to define record types with
"the same fields plus some others":

(** point2.mli **)
type point2 = { x : float;
                y : float }

(** **)
type point3 = { include Point2.point2;
                z : float }

(* which would be exactly equivalent as writing *)
type point3 = { x : float;
                y : float;
                z : float }

Some disavantadges:
- same field labels but no subtyping
  (and all the usual problems that we don't have with classes and objects)

Some advantages:
- can be used where objects cannot (input/output_value are possible)
- makes some type definitions more clear

My initial problem is to input/output objects with a minimum of efforts.
If we have one module for each class, with some hand-written conversion
from/to record types, maybe it would be convenient to have a
such a pseudo-inheritance system for record types.

Any experience with this kind of problem?

Unless Marshal becomes available for objects?...

-- Martin

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: