<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2002/12/5f28c0d6c5868bcafd8e8dd4e701f0b3"
  from="onlyclimb &lt;onlyclimb@1...&gt;"
  author="onlyclimb"
  date="2002-12-09T13:21:02"
  subject="[Caml-list] How to throw away oop?"
  prev="2002/12/3407fde4a77f5618c32cb0a63e7d9ed0"
  next="2002/12/40d47b1fdb99fb42dfd9ca964f446527"
  next-in-thread="2002/12/40d47b1fdb99fb42dfd9ca964f446527"
  prev-thread="2002/12/8ea889634a390e77255fa06015627be4"
  next-thread="2002/12/4f26c91200b871153ac571f4e71c7d1f"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] How to throw away oop?">
<msg 
  url="2002/12/5f28c0d6c5868bcafd8e8dd4e701f0b3"
  from="onlyclimb &lt;onlyclimb@1...&gt;"
  author="onlyclimb"
  date="2002-12-09T13:21:02"
  subject="[Caml-list] How to throw away oop?">
<msg 
  url="2002/12/40d47b1fdb99fb42dfd9ca964f446527"
  from="Olivier Andrieu &lt;andrieu@i...&gt;"
  author="Olivier Andrieu"
  date="2002-12-09T14:10:35"
  subject="Re: [Caml-list] How to throw away oop?">
<msg 
  url="2002/12/4456fccbbadad6cb7c7b36cf182fe3aa"
  from="brogoff@s..."
  author="brogoff@s..."
  date="2002-12-09T18:44:06"
  subject="Re: [Caml-list] How to throw away oop?">
</msg>
</msg>
<msg 
  url="2002/12/b35f796e88ae22506184f5b230eccf45"
  from="Didier Le Botlan &lt;lebotlan@b...&gt;"
  author="Didier Le Botlan"
  date="2002-12-09T21:17:12"
  subject="Re: [Caml-list] How to throw away oop?">
</msg>
</msg>
</thread>

<contents>
  Dear Caml List:
        I think it is an old question. but it really bother me quite 
much .  Since i have a java background and touched ML not long, i found 
it is  hard not to think in a OOP way in some cases. (even though OCaml 
has an OO system, i feel  that only  the Module style  is the true way 
of programming in Ocaml, so i tried not to use classes as possible )
 Here is a situation i can not overcome:  for example
in a OOP style.:
  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
  I want to get the length of the Seq.   so  in OOP Style . we can 
define a function :
  val  length : #seq -&gt; int   to solve the problem .   or just use 
inheritance  seq#length
However if do like above , i must define say  class dna    or class 
protein  

Now i want not to use classes. How can i achieve the same effect?
Maybe i can use functor  like
module DefautSeq = Seq.Make ( DefaultSeqIntf : SeqIntf) struct end
module DNA = Seq.Make ( DNAIntf : SeqIntf )  struct    end
module Protein = Seq.Make (DNAIntf : SeqIntf) struct     end
now how to get the length of such seqs ?
(in fact length is usually included in the SeqIntf  .  here  i only to 
show a simple case.  
  for example Chromasome is a kind of DNA ,  some funtions only for  
Chromasome and DNA not suitable for Protein
  so those functions surely will not be included in SeqIntf .  here 
length () refers to such functions  )
if i do like this,
val length : DefaultSeq.t -&gt; int.
DNA.t  will not be accepted by such function . only DefaultSeq .t accepted
I have tryied to use  
 module DefaultSeq  = DNA  before the  length function .  It is OK
But  First  it is not elegant .
 Secd , if module DefaultSeq  = DNA is after the length function.  It 
will not work.
Third ,  sometime you must restore the orignal module , it is tedious 
also not elegant :-(

And maybe can genrate a new functor  LENGTH . bu t i can not image to 
generate a module in  every case just a proper function will do !

Then,  How can i do ?  
Thanks
                               climb




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

</contents>

</message>

