From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: weis Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id WAA31895 for caml-redistribution@pauillac.inria.fr; Sun, 7 Nov 1999 22:45:38 +0100 (MET) Resent-Message-Id: <199911072145.WAA31895@pauillac.inria.fr> Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA23929 for ; Sun, 7 Nov 1999 15:21:19 +0100 (MET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.8.7/8.8.7) with ESMTP id PAA01765; Sun, 7 Nov 1999 15:21:16 +0100 (MET) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id PAA32702; Sun, 7 Nov 1999 15:21:16 +0100 (MET) Message-ID: <19991107152116.28401@pauillac.inria.fr> Date: Sun, 7 Nov 1999 15:21:16 +0100 From: Xavier Leroy To: Valentin Bonnard , caml-list@inria.fr Subject: Re: =?iso-8859-1?Q?Problème_d'oubli_dans_un_module_=5BA_problem_with_modul?= =?iso-8859-1?Q?es=5D?= References: <19991030044139.30767@soling.ens.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.89.1 In-Reply-To: <19991030044139.30767@soling.ens.fr>; from Valentin Bonnard on Sat, Oct 30, 1999 at 04:41:39AM +0200 Resent-From: weis@pauillac.inria.fr Resent-Date: Sun, 7 Nov 1999 22:45:37 +0100 Resent-To: caml-redistribution@pauillac.inria.fr > [ I can still use ``get'': ] > > # let z = Obj.magic y;; > val z : '_a = > # print_int (z#get);; > 3- : unit = () > > [ And it works, I understand that it is guarantied to work. ] No, it's not. To begin with, any piece of code that contains "Obj.magic" is not guaranteed to work. (You'd be amazed at how many type-based compiler optimizations can be broken by innocuous-looking uses of Obj.magic. I spent one full day once tracking a GC "bug" in ocamlopt that had been reported to us; the "bug" turned out to be one such use of Obj.magic in the user's code. Since then, I've been grepping for "Obj.magic" in every bug report that we get, and throwing away immediately those where it occurs. You've been warned!) Second, you're making assumptions on how subtyping coercions are compiled. (See below.) > [ Now, I will try to do the same thing with modules. ] > [ Now, how can I use ``get'' ? ] > # (Obj.magic Y: sig val get : int end).get;; You can't. First of all, there is no module-level equivalent of Obj.magic. (Thanks God.) Second, the run-time representation of Y really contains no "get" member, it's just the empty tuple. Subtyping between modules is coercitive, meaning that at the point where a module is viewed with a supertype, the run-time representation of the module changes to reflect the change in type. This allows to compile accesses to structure fields by offsets (computed from the signature of the structure) rather than by name, which is good for efficiency. In contrast, subtyping between objets doesn't change the object representation in the OCaml compiler. There are several reasons for this, one being that it makes it much easier to preserve object identity (for objects having mutable instance variables). But one could come up with compilation schemes where subsumption on objects changes the internal representation. > [ I'd like to access the forgotten get member. > In case you are wondering, yes, this need arises > from a real problem. ] What about looking for a type-safe solution to that real problem? - Xavier Leroy