Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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-20 (12:56)
From: Brian Smith <blsmith@b...>
Subject: Re: [Caml-list] Five Questions about Objects
YAMAGATA yoriyuki wrote:
> From: Oleg <>
> 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 Archives:
Bug reports: FAQ:
Beginner's list: