caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Problème d'oubli dans un module [A problem with modules]
@ 1999-10-30  2:41 Valentin Bonnard
  1999-11-07 14:21 ` Xavier Leroy
  0 siblings, 1 reply; 2+ messages in thread
From: Valentin Bonnard @ 1999-10-30  2:41 UTC (permalink / raw)
  To: caml-list

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



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1999-11-07 21:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-10-30  2:41 Problème d'oubli dans un module [A problem with modules] Valentin Bonnard
1999-11-07 14:21 ` Xavier Leroy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).