Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] How to throw away oop?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Olivier Andrieu <andrieu@i...>
Subject: Re: [Caml-list] How to throw away oop?
 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.

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

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