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
on polymorphic compare and objects
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-09-03 (06:31)
From: Alain Frisch <alain@f...>
Subject: Re: [Caml-list] on polymorphic compare and objects
Peng Zang wrote:
> For objects, we require that all objects
> implement an equal method that satisfies the semantic contract.

How do you ensure that the method is indeed implemented and has the 
correct type?

A more robust approach to attaching custom generic operations to 
arbitrary data would be to introduce the equivalent of custom blocks, 
but for OCaml data. This probably amounts to reserving a new GC tag and 
deciding on a memory layout (e.g. a block with this tag has two fields: 
the underlying value and a dictionary of generic functions). Then simple 
modules in stdlib could expose a well-typed interface (ensuring that the 
type of the dictionary's functions is compatible with the type of the 
underlying values). It would even be possible to expose the resulting 
blocks as values of a private record type with two fields, so as to 
preserve pattern matching on the underlying value.