English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Re: [Caml-list] Width subtyping
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2009-05-31 (05:18)
From: Dave Benjamin <dave@r...>
Subject: Re: [Caml-list] Width subtyping
Dario Teixeira wrote:
> Hi,
>> There must be something that escapes me.... This seems to be an
>> example where ocaml objects really shine because of the structural
>> typing (i.e. an object is defined by the its structure):
> You are right.  I was probably too fixated on the OOP way of doing this,
> translating record fields into object fields and the functions acting on
> records into object methods.  Your solution, where record fields become object
> methods and external functions act on objects that match a certain structure,
> does solve the inconveniences I mentioned before.  But objects are still
> a somewhat heavier solution, right?

Heavier in terms of efficiency, or syntax? If you mean the latter, I 
wonder if a camlp4 syntax extension might help ease the burden; perhaps 
something like:

   #{x=5; y=6}

could be translated to:

   object method x = 5 method y = 6 end

and then you could benefit from a lightweight syntax and still get the 
static type checking.