caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Valentin Bonnard <bonnard@clipper.ens.fr>
To: caml-list@inria.fr
Subject: Problème d'oubli dans un module [A problem with modules]
Date: Sat, 30 Oct 1999 04:41:39 +0200	[thread overview]
Message-ID: <19991030044139.30767@soling.ens.fr> (raw)

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



             reply	other threads:[~1999-11-03 20:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-10-30  2:41 Valentin Bonnard [this message]
1999-11-07 14:21 ` Xavier Leroy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=19991030044139.30767@soling.ens.fr \
    --to=bonnard@clipper.ens.fr \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).