<?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/4456fccbbadad6cb7c7b36cf182fe3aa"
  from="brogoff@s..."
  author="brogoff@s..."
  date="2002-12-09T18:44:06"
  subject="Re: [Caml-list] How to throw away oop?"
  prev="2002/12/40d47b1fdb99fb42dfd9ca964f446527"
  next="2002/12/b35f796e88ae22506184f5b230eccf45"
  prev-in-thread="2002/12/40d47b1fdb99fb42dfd9ca964f446527"
  next-in-thread="2002/12/b35f796e88ae22506184f5b230eccf45"
  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>
On Mon, 9 Dec 2002, Olivier Andrieu wrote:
&gt;  onlyclimb [Monday 9 December 2002] :
&gt;  &gt;   DNA and Protein can be a subclass of Seq. And in fact there are many 
&gt;  &gt;  kind of sequences , so we can suppose the number of the kind of Seq is 
&gt;  &gt; infinite. ie. the subclasses of Seq can be infinite.  and DNA and 
&gt;  &gt; Protein are just two of them
&gt; 
&gt; Do you really think you'll have to subclass your Seq often ? I mean,
&gt; you have DNA, proteins and this is it (you can add RNA if you want to
&gt; nitpick). In this case, ie when your datatypes are fixed and you're not
&gt; 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

&gt; module DNA = 
&gt;   type t = ...
&gt;   let length = ...
&gt; end
&gt; 
&gt; module Protein = 
&gt;   type t = ...
&gt;   let length = ...
&gt; end
&gt; 
&gt; and you can build a generic module for functions common in DNA and
&gt; Protein :
&gt; 
&gt; module Seq = 
&gt;   type t = 
&gt;    | DNA of DNA.t
&gt;    | Protein of Protein.t
&gt;   let length = function
&gt;    | DNA s -&gt; DNA.length s
&gt;    | Protein s -&gt; Protein.length s
&gt; end

and, if we had true generics as in GCaml, we could write this 

generic length = 
  DNA.t -&gt; DNA.length
| Protein -&gt; 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

</contents>

</message>

