Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Allow declaring classes "final" so self type has no type variables?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: james woodyatt <jhw@w...>
Subject: Re: [Caml-list] Allow declaring classes "final" so self type has no type variables?
On Friday, Sep 6, 2002, at 13:38 US/Pacific, Alessandro Baretta wrote:
> james woodyatt wrote:
>> On Friday, Sep 6, 2002, at 12:12 US/Pacific, Tim Freeman wrote:
>>>
>>> Any comments on whether this is a good idea?
>>
>> Hide the class with a module signature.  Publish only the class type 
>> and one or more functions for constructing objects.
>
> I don't think this is what he meant. I think he would like to 
> "finalize" a class for efficiency purposes as opposed to "safety" 
> purposes. He is asking for some compiler magic.

The opportunity to optimize method dispatch simply isn't there.  The 
reason is that two objects with identical class types need not have 
methods with the same definition.

> 	# class a = object method f = print_string "a\n" end;;
> 	class a : object method f : unit end
> 	# class b = object method f = print_string "b\n" end;;
> 	class b : object method f : unit end
> 	# let print (p : a) = p#f;;
> 	val print : a -> unit = <fun>
> 	# print (new b);;
> 	b
> 	- : unit = ()

In the above excerpt, class a and class b are different classes with 
equivalent class types.  The function 'print' may look like it requires 
objects constructed of class a, but all it really requires is objects 
of class type a (and since class type b is equivalent to class type a, 
objects of class b will work just as well).

And anyway... last I checked, method dispatch was not the low-hanging 
fruit for optimizing Ocaml code with objects and classes.  The size of 
class initializers (generated by the compiler and executed in enclosing 
module initializers) are where it seems to me the big opportunities are 
to be had.


-- 
j h woodyatt <jhw@wetware.com>
markets are only free to the people who own them.

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