<?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="2009/01/bd2154c070fbbf0db327cfe1ac2f06b8"
  from="Mark Shinwell &lt;mshinwell@j...&gt;"
  author="Mark Shinwell"
  date="2009-01-14T15:52:55"
  subject="Re: [Caml-list] Caml implementation of the relaxed value restriction"
  prev="2009/01/f1aad22c4a589642a3bb869a498b8209"
  next="2009/01/14d8d8d728ebd37e4a9f9ddac58fed93"
  prev-in-thread="2009/01/eed2238e7a54f55ec6c038598c55045b"
  prev-thread="2009/01/6cf79b75301fab6a2690970d5f9afce6"
  next-thread="2009/01/05bc548e588fe9c3a7b00f01c10770eb"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="Caml implementation of the relaxed value restriction">
<msg 
  url="2009/01/eed2238e7a54f55ec6c038598c55045b"
  from="Julien SIGNOLES &lt;julien.signoles@c...&gt;"
  author="Julien SIGNOLES"
  date="2009-01-14T15:31:18"
  subject="Caml implementation of the relaxed value restriction">
<msg 
  url="2009/01/bd2154c070fbbf0db327cfe1ac2f06b8"
  from="Mark Shinwell &lt;mshinwell@j...&gt;"
  author="Mark Shinwell"
  date="2009-01-14T15:52:55"
  subject="Re: [Caml-list] Caml implementation of the relaxed value restriction">
</msg>
</msg>
</thread>

<contents>
On Wed, Jan 14, 2009 at 04:31:24PM +0100, Julien SIGNOLES wrote:
&gt; In the article "Many Holes in Hindley-Milner" [1], Sam Lindley claims
&gt; that the type of x is ('a * 'a s, int) NList.t in the following ocaml
&gt; program because of Garrigue's relaxed value restriction [2].
&gt; ==========
&gt; type 'a s
&gt; 
&gt; module NList : sig
&gt;   type (+'length, +'elem_type) t
&gt;   val nil : ('m*'m, 'a) t
&gt;   val cons: 'a * ('m*'n, 'a) t -&gt; ('m*'n s,'a) t
&gt; end = struct
&gt;   type ('i,'a) t = 'a list
&gt;   let nil = []
&gt;   let cons (x, l) = x :: l
&gt; end
&gt; 
&gt; let x = NList.cons (1, NList.nil)
&gt; ==========
&gt; 
&gt; But, both with ocaml v3.10.2 and ocaml v3.12.0+dev1 (2008-12-03) (that
&gt; is the current cvs version), the infered type of [x] only contains a
&gt; weak type variable: ('_a * '_a s, int) NList.t.
&gt; 
&gt; I quickly look at the typing rules introduced by Jacques Garrigue in [2]
&gt; and it seems to me that Sam Lindley is right: [x] is generalisable in
&gt; the above program.
&gt; 
&gt; So, what's wrong here?

You need to say "type +'a s", otherwise the compiler (since "s" is an
abstract type) cannot know the variance of that type parameter inside a
value of type 'a s.  That information is needed to determine how to
generalize the type of x.

Mark

</contents>

</message>

