<?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/9d191dbdc8b05bc3b233f36a11ac6504"
  from="nadji@n..."
  author="nadji@n..."
  date="2002-07-14T23:52:07"
  subject="[Caml-list] polymorphic methods"
  prev="2002/07/51d1044e37baa6970179401f44e15323"
  next="2002/07/1b29cfdfd19552b03e846f44303aa30e"
  next-in-thread="2002/07/6c4a835c1b222da5d3b140bc24cc7dbf"
  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>
Hello,

While playing with the current cvs version of ocaml (3.04+15),
several questions came to me concerning the semantics of
polymorphic methods. For example :

# class c = object
  method ~m: 'a . unit -&gt; 'a -&gt; 'a = fun _ x -&gt; x
end;;
    class c : object method m : unit -&gt; 'a -&gt; 'a end
# let f = (new c)#m ();;
val f : '_a -&gt; '_a = &lt;fun&gt;

Shouldn't the type of f be : 'a -&gt; 'a  ?
(Would it be sound/implementable/easy to add ?)

Second question:
# class ['a] d = object
  method m: 'a -&gt; 'a = fun x -&gt; x
end;;
    class ['a] d : object method m : 'a -&gt; 'a end
# class subd = object
  method ~m: 'a. 'a -&gt; 'a = fun x -&gt; x
end;;
    class subd : object method m : 'a -&gt; 'a end
# let v = (new subd :&gt; 'a d);;
Characters 9-17:
  let v = (new subd :&gt; 'a d);;
           ^^^^^^^^
This expression cannot be coerced to type 'a d = &lt; m : 'a -&gt; 'a &gt;;
it has type subd = &lt; m : 'b. 'b -&gt; 'b &gt; but is here used with type 'a d

Or even the easier :
# class d' = object
  method m x = x + 0
end;;
    class d' : object method m : int -&gt; int end
# let v' = (new subd :&gt; d');;
Characters 10-18:
  let v' = (new subd :&gt; d');;
            ^^^^^^^^
This expression cannot be coerced to type d' = &lt; m : int -&gt; int &gt;;
it has type subd = &lt; m : 'a. 'a -&gt; 'a &gt; but is here used with type d'

But the type ('b. 'b -&gt; 'b) is more general than ('a -&gt; 'a)
or (int -&gt; int), no ?
Can someone give me some hints why I can't coerce subd ?

Btw, thanks for the upcoming release, it seems _really_ excellent !
Nadji

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

