<?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/6c4a835c1b222da5d3b140bc24cc7dbf"
  from="Jacques Garrigue &lt;garrigue@k...&gt;"
  author="Jacques Garrigue"
  date="2002-07-15T01:05:13"
  subject="Re: [Caml-list] polymorphic methods"
  prev="2002/07/1b29cfdfd19552b03e846f44303aa30e"
  next="2002/07/3132c286510f600ffca82535bf00c73b"
  prev-in-thread="2002/07/9d191dbdc8b05bc3b233f36a11ac6504"
  next-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>
From: nadji@noos.fr

&gt; While playing with the current cvs version of ocaml (3.04+15),
&gt; several questions came to me concerning the semantics of
&gt; polymorphic methods. For example :
&gt; 
&gt; # class c = object
&gt;   method m: 'a . unit -&gt; 'a -&gt; 'a = fun _ x -&gt; x
&gt; end;;
&gt;     class c : object method m : unit -&gt; 'a -&gt; 'a end
&gt; # let f = (new c)#m ();;
&gt; val f : '_a -&gt; '_a = &lt;fun&gt;
&gt; 
&gt; Shouldn't the type of f be : 'a -&gt; 'a  ?
&gt; (Would it be sound/implementable/easy to add ?)

Unsound. RTFM (polymorphism restricted to values)
Try "let f x = (new c)#m () x"
But I don't see why you need ().

&gt; Second question:
&gt; # class ['a] d = object
&gt;   method m: 'a -&gt; 'a = fun x -&gt; x
&gt; end;;
&gt;     class ['a] d : object method m : 'a -&gt; 'a end
&gt; # class subd = object
&gt;   method ~m: 'a. 'a -&gt; 'a = fun x -&gt; x
&gt; end;;
&gt;     class subd : object method m : 'a -&gt; 'a end
&gt; # let v = (new subd :&gt; 'a d);;
&gt; Characters 9-17:
&gt;   let v = (new subd :&gt; 'a d);;
&gt;            ^^^^^^^^
&gt; This expression cannot be coerced to type 'a d = &lt; m : 'a -&gt; 'a &gt;;
&gt; it has type subd = &lt; m : 'b. 'b -&gt; 'b &gt; but is here used with type 'a d
&gt; 
&gt; Or even the easier :
&gt; # class d' = object
&gt;   method m x = x + 0
&gt; end;;
&gt;     class d' : object method m : int -&gt; int end
&gt; # let v' = (new subd :&gt; d');;
&gt; Characters 10-18:
&gt;   let v' = (new subd :&gt; d');;
&gt;             ^^^^^^^^
&gt; This expression cannot be coerced to type d' = &lt; m : int -&gt; int &gt;;
&gt; it has type subd = &lt; m : 'a. 'a -&gt; 'a &gt; but is here used with type d'
&gt; 
&gt; But the type ('b. 'b -&gt; 'b) is more general than ('a -&gt; 'a)
&gt; or (int -&gt; int), no ?
&gt; Can someone give me some hints why I can't coerce subd ?

Sorry, but there is no handling of instanciation via subtyping.
Currently subtyping and instanciation are orthogonal concepts: you
cannot subtype in an .mli, and you cannot instanciate an
explicitly polymorphic type when subtyping.
I believe it's correct, but you won't make me write the code without a
proof :-)

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

