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
adding methods to object
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-04-01 (06:34)
From: Jacques Garrigue <garrigue@m...>
Subject: Re: [Caml-list] adding methods to object
From: "Jacques Le Normand" <rathereasy@gmail.com>

> is it possible to add methods to an object?
> in other words, if an object has type <a:b,c:d>, is it possible to create an
> object of type <a:b,c:d,e:f> ?

No, you can only add methods to classes.
The only thing you can do with an object is build a wrapper object or
class, which forwards original methods to the base object:

let wrap o =
    method a = o#a
    method c = o#c
    method e = ...

Jacques Garrigue