Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
From: Brian Smith <blsmith@b...>
Subject: Re: [Caml-list] Five Questions about Objects
YAMAGATA yoriyuki wrote:
> From: Oleg <oleg_inconnu@myrealbox.com>
> Subject: [Caml-list] Five Questions about Objects
> Date: Sat, 13 Jul 2002 09:42:47 -0400
> 
> 
>>let point a b = 
>>  object
>>    val x = a
>>    val y = b
>>    method get () = (x, y)
>>  end;;
>>
> 
> I think You can't do like this.  object ... end is a part of a class
> definition, and not an ordinary expression.
> 
> However, I wonder why a class is necessary in the first place.  I'm
> not familiar with the theory of OOP, but I feel like direct creation
> of objects is possible in functional languages.

I think that the "class" and "class type" constructs are useful when 
expressing the relationship between types/classes. For example, "let 
point a b..." defines a function that creates an object. But, what does 
(x :> point) mean when point is a function instead of a class type? If 
anything, I would thing that (f :> g) would mean that the return type 
and parameter types of f follow the covariant/contravariant rules for 
methods. Similarly, what would the #point construct mean?

Also, class types are types, and classes define implicit types, so I 
think that the class syntax should be close to the syntax for defining 
other kinds of types, instead of the syntax for defining functions.

- Brian
-------------------
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