<?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/07/c9430e65561feff15e8b94b431ac0365"
  from="nadji@n..."
  author="nadji@n..."
  date="2002-07-15T16:24:31"
  subject="Re: [Caml-list] polymorphic methods"
  prev="2002/07/a26dafef4b887630fd93241adaf9e1e6"
  next="2002/07/873b748069a397a4d4473a9c160fe422"
  prev-in-thread="2002/07/3132c286510f600ffca82535bf00c73b"
  prev-thread="2002/07/51d1044e37baa6970179401f44e15323"
  next-thread="2002/07/1b29cfdfd19552b03e846f44303aa30e"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] polymorphic methods">
<msg 
  url="2002/07/9d191dbdc8b05bc3b233f36a11ac6504"
  from="nadji@n..."
  author="nadji@n..."
  date="2002-07-14T23:52:07"
  subject="[Caml-list] polymorphic methods">
<msg 
  url="2002/07/6c4a835c1b222da5d3b140bc24cc7dbf"
  from="Jacques Garrigue &lt;garrigue@k...&gt;"
  author="Jacques Garrigue"
  date="2002-07-15T01:05:13"
  subject="Re: [Caml-list] polymorphic methods">
<msg 
  url="2002/07/3132c286510f600ffca82535bf00c73b"
  from="Brian Smith &lt;brian-l-smith@u...&gt;"
  author="Brian Smith"
  date="2002-07-15T02:17:45"
  subject="Re: [Caml-list] polymorphic methods">
</msg>
<msg 
  url="2002/07/c9430e65561feff15e8b94b431ac0365"
  from="nadji@n..."
  author="nadji@n..."
  date="2002-07-15T16:24:31"
  subject="Re: [Caml-list] polymorphic methods">
</msg>
</msg>
</msg>
</thread>

<contents>
Jacques Garrigue wrote:

&gt; &gt; # let f = (new c)#m ();;
&gt; &gt; val f : '_a -&gt; '_a = &lt;fun&gt;
&gt;
&gt; Unsound. RTFM (polymorphism restricted to values)
&gt; Try "let f x = (new c)#m () x"
&gt;

Oups, sorry. I did'nt recognize this classical problem ...
In fact this example was an attempt to simplify my
next question, but I can see now that they are not related.

&gt; But I don't see why you need ().
&gt;

You're right. It was there for historical reasons and I had
not realized I did'nt need an argument anymore.

&gt; &gt; Can someone give me some hints why I can't coerce subd ?
&gt;
&gt; Sorry, but there is no handling of instanciation via subtyping.
&gt; Currently subtyping and instanciation are orthogonal concepts: you
&gt; cannot subtype in an .mli, and you cannot instanciate an
&gt; explicitly polymorphic type when subtyping.

That's a shame because if one tries to use objects for manipulating
lists :

# exception Emptylist

class type ['a] olist = object
  method hd : 'a
  method tl : 'a olist
end

 class nil = object
  method ~hd: 'a . 'a = raise Emptylist
  method ~tl: 'a . 'a olist = raise Emptylist
end

let objnil = (new nil :&gt;  'a olist);;
Characters 14-21:
  let objnil = (new nil :&gt;  'a olist);;
                ^^^^^^^
This expression cannot be coerced to type
  'a olist = &lt; hd : 'a; tl : 'a olist &gt;;
it has type nil = &lt; hd : 'b. 'b; tl : 'c. 'c olist &gt;
but is here used with type &lt; hd : 'a; tl : 'a #olist &gt;.
This simple coercion was not fully general. Consider using a double coercion.

Too bad. Also this is the first time I get this error message. Does it mean that
I have to try something like (a : b :&gt; c) ? If not, what is a double coercion,
and
can you give a case where is it needed ?


&gt;
&gt; I believe it's correct, but you won't make me write the code without a
&gt; proof :-)

This is why I like Ocaml :)

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

