From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA10605; Mon, 9 Dec 2002 19:44:06 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 TAA10374 for ; Mon, 9 Dec 2002 19:44:02 +0100 (MET) Received: from grace.speakeasy.org (grace.speakeasy.org [216.254.0.2]) by nez-perce.inria.fr (8.11.1/8.11.1) with SMTP id gB9Ii1105686 for ; Mon, 9 Dec 2002 19:44:01 +0100 (MET) Received: (qmail 12969 invoked by uid 36130); 9 Dec 2002 18:43:59 -0000 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 9 Dec 2002 18:43:59 -0000 Date: Mon, 9 Dec 2002 10:43:59 -0800 (PST) From: brogoff@speakeasy.net To: Olivier Andrieu cc: onlyclimb , "caml-list@inria.fr" Subject: Re: [Caml-list] How to throw away oop? In-Reply-To: <15860.42055.229312.122122@akasha.ijm.jussieu.fr> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Mon, 9 Dec 2002, Olivier Andrieu wrote: > onlyclimb [Monday 9 December 2002] : > > DNA and Protein can be a subclass of Seq. And in fact there are many > > kind of sequences , so we can suppose the number of the kind of Seq is > > infinite. ie. the subclasses of Seq can be infinite. and DNA and > > Protein are just two of them > > Do you really think you'll have to subclass your Seq often ? I mean, > you have DNA, proteins and this is it (you can add RNA if you want to > nitpick). In this case, ie when your datatypes are fixed and you're not > going to extend them, you can simply use a variant type. In the case of a function like "length", there are certainly a lot of things which satisfy it. Most of the time, writing Foo.length is OK, but there are certainly times when it is less clear IMO. It seems what the original poster misses here isn't so much OOP but overloading, since there is no late-binding/open-recursion/implementation-inheritance though it turns out that OCaml's object system gives you something like overloading. I prefer Olivier's solution in this case > module DNA = > type t = ... > let length = ... > end > > module Protein = > type t = ... > let length = ... > end > > and you can build a generic module for functions common in DNA and > Protein : > > module Seq = > type t = > | DNA of DNA.t > | Protein of Protein.t > let length = function > | DNA s -> DNA.length s > | Protein s -> Protein.length s > end and, if we had true generics as in GCaml, we could write this generic length = DNA.t -> DNA.length | Protein -> Protein.length directly without the tagging and untagging. This would be my preferred solution if it were in the language. -- 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