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] does class polymorphism need to be so complicated?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: brogoff@s...
Subject: Re: [Caml-list] does class polymorphism need to be so complicated?
On Wed, 20 Aug 2003, Benjamin Geer wrote:
> wrote:
> > If you want to solve your problem, you'll need to coerce,
>  > [...]
> > A solution using polymorphic methods is sketched next,
> These are the two options I described in my original post.  Both are 
> inconvenient.  My original questions remain:

Sorry, I didn't read your original post, only Brian Hurt's reply to it. 
Jacques Garrigue explained the reasons why it is hard to do everything you 
want in OCaml, but I still think you are being a bit harsh. 

First, calling the methods through functions is not the uncontested evil that 
you make it out to be.

Second, I don't think that there would be a big gain in productivity by 
changing the polymorphic method syntax. As JG points out, it's not too much 
work to ensure that the user of the code doesn't need to use that syntax, as 
long as the library author is careful, so for instance 

class virtual processor =
     method virtual process : 'a . (#thing as 'a ) -> unit

class thing_processor =
     inherit processor
     method process obj =
         print_string (string_of_int (obj#foo 1));
         print_string obj#bar;
         print_string (string_of_bool obj#baz);
         print_endline ""
   end ;;

and in any realistic program the virtuals will be in some separate module. 
Having had a foot in the Ada world, I appreciate this little bit of verbosity 
in which the typing is all laid out. My problem is not usually the issue of 
changing text, but the issue of remembering what the types of things are. 

-- Brian

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: