English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] Five Questions about Objects
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-07-13 (13:40)
From: Oleg <oleg_inconnu@m...>
Subject: [Caml-list] Five Questions about Objects

A few questions on objects:

1) Why does the following code define a polymorphic class

 class point a b = 
      val x = a
      val y = b

but adding "method get () = (x, y)" results in type errors only resolvable by 
specifying types with "class ['a, 'b] point (a:'a) (b:'b)" ? Why doesn't 

 class point a b = 
      val x = a
      val y = b
      method get () = (x, y)

give me a polymorphic class?

2) What is the point of "class" and "new" keywords? How are they better than 
"let" ? E.g.

let point a b = 
    val x = a
    val y = b
    method get () = (x, y)

let my_point = point 3 7;; 
let many_float_points = Array.make 100 (point 4.0 3.0);;

3) Is it possible to access object datafields directly or only through 

4) Can I construct an object that the following function f would accept?
# let f a = a#m1 (); a#b#m2 ();;
val f : < b : < m2 : unit -> 'a; .. >; m1 : unit -> 'b; .. > -> 'a = <fun>

I tried the obvious (to me) and it doesn't work. What is the precedence and 
associativity of #?

5) What is the current state of marshalling objects? Is Jacques's patch going 
to be used in the upcoming O'Caml version or is it too untested? 

To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners