From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA02869 for caml-redistribution; Thu, 15 May 1997 11:41:51 +0200 (MET DST) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id AAA24228 for ; Thu, 15 May 1997 00:11:10 +0200 (MET DST) Received: from haven.uchicago.edu (root@haven.uchicago.edu [128.135.12.3]) by nez-perce.inria.fr (8.8.5/8.7.3) with ESMTP id AAA29698 for ; Thu, 15 May 1997 00:11:07 +0200 (MET DST) Received: from midway.uchicago.edu (root@midway.uchicago.edu [128.135.12.12]) by haven.uchicago.edu (8.8.5/8.8.5) with ESMTP id RAA24380 for ; Wed, 14 May 1997 17:11:03 -0500 (CDT) Received: from kimbark.uchicago.edu (root@kimbark.uchicago.edu [128.135.12.52]) by midway.uchicago.edu (8.8.5/8.8.3) with ESMTP id RAA03056 for ; Wed, 14 May 1997 17:01:51 -0500 (CDT) Received: from kimbark.uchicago.edu (4208@localhost [127.0.0.1]) by kimbark.uchicago.edu (8.8.5/8.8.3) with ESMTP id RAA04549 for ; Wed, 14 May 1997 17:01:49 -0500 (CDT) Message-Id: <199705142201.RAA04549@kimbark.uchicago.edu> To: caml-list@inria.fr Subject: functors vs classes Date: Wed, 14 May 1997 17:01:48 -0500 From: Lyn A Headley Sender: weis hi, In the caml programming language we are offered an (unprecedented) choice between two varieties of modular polymorphism, classes and functors. Each offers distinct advantages, and yet in a way it seems that each supports a different _style_ of programming. In my limited experience it seems that most people opt to focus on functors for their modularization needs, and make little or no use of the objective stuff. How do others see this? In my case I believe that both styles offer advantages, and that it would behoove the prudent caml programmer to develop a style which uses each paradigm, in the appropriate situation. The question is, how can we identify which situation deserves which representation? Obviously inheritance is a main difference; object-oriented techniques are appropriate for modeling trees of subclasses descended from a common base. And yet, so are variant types, as long as the tree doesn't get too deep. So it seems that if a type could have many layers of inheritance, maybe an object would be the best representation. Otherwise, I'd take the conceptual simplicity, readability and pattern matching that go along with variant types. While both models offer polymorphism, the form taken is different. It seems that functors are appropriate when a finite number of program units depend on or contain each other. Objective polymorphism, on the other hand, seems most effective (again) when programs contain various instanciations of objects related hierarchichally. I'm hoping to get some discussion on this issue since (a) I'd like a clearer grasp of the material and (b) I imagine this is a common question for new ocaml programmers, and I think it would be nice for them if we could flesh out a document that describes the various qualities and advantages of each paradigm. Lyn