Date: Sat, 30 Oct 1999 04:41:39 +0200
From: Valentin Bonnard <bonnard@clipper.ens.fr>
To: caml-list@inria.fr
Subject: =?iso-8859-1?Q?Problème_d'oubli_dans_un_module_=5BA_problem_with_modul?=
Avec les objets, je peux faire ceci:
[ With objects, I can do this: ]
# class vide = object end
and foo = object method get = 3 end;;
class vide : object end
class foo : object method get : int end
Je crée un objet avec une méthode get:
[ I create an object with a method called get: ]
# let x = new foo;;
val x : foo = <obj>
J'oublie get:
[ I forget ``get'': ]
# let y = (x :> vide);;
val y : vide = <obj>
Je vérifie que get n'est plus là:
[ And ``get'' isn't there anymore: ]
# y#get;;
This expression has type vide
It has no method get
J'utilise get quand même:
[ I can still use ``get'': ]
# let z = Obj.magic y;;
val z : '_a = <poly>
# print_int (z#get);;
3- : unit = ()
[ And it works, I understand that it is guarantied to
work. ]
Maintenant, les modules.
[ Now, I will try to do the same thing with modules. ]
# module type vide = sig end;;
module type vide = sig end
Je crée un module avec get:
[ I create a module with a member called ``get'': ]
# module Foo = struct let get = 3 end;;
module Foo : sig val get : int end
J'oublie get:
[ Again, I forget the ``get'' member: ]
# module Y = (Foo: vide);;
module Y : vide
Je vérifie que get n'est plus là:
[ I can't access the forgotten member: ]
# Y.get;;
Unbound value Y.get
Comment utiliser get quand même ?
[ Now, how can I use ``get'' ? ]
# (Obj.magic Y: sig val get : int end).get;;
Syntax error
Je voudrais récupérer get.
Cette question vient d'un problème réel.
[ I'd like to access the forgotten get member.
In case you are wondering, yes, this need arises
from a real problem. ]
--Valentin Bonnard
This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:28 MET