Version française
Home     About     Download     Resources     Contact us    
Browse thread
Problème_d'oubli_dans_un_module_[A_problem_with_modul es]
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Valentin Bonnard <bonnard@c...>
Subject: Problème_d'oubli_dans_un_module_[A_problem_with_modul es]
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