<?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/26c5a06033dc1589398fce69582e3431"
  from="Xavier Leroy &lt;Xavier.Leroy@i...&gt;"
  author="Xavier Leroy"
  date="2009-01-11T16:32:04"
  subject="Re: [Caml-list] Why does value restriction not apply to the empty list ?"
  prev="2009/01/c69b845f9974f5a4f59496ff3c48f981"
  next="2009/01/bdb3d4c35cff66ea7be1c275b5f87645"
  prev-in-thread="2009/01/455d25be895d8c744758490fd4f28a1f"
  prev-thread="2009/01/28ab596a711780efefe765f0d5873dc1"
  next-thread="2009/01/bdb3d4c35cff66ea7be1c275b5f87645"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="Why does value restriction not apply to the empty list ?">
<msg 
  url="2009/01/df2de1846d5559d3faa62662b822bba6"
  from="Antoine Delignat-Lavaud &lt;antoine.delignat-lavaud@d...&gt;"
  author="Antoine Delignat-Lavaud"
  date="2009-01-10T11:34:50"
  subject="Why does value restriction not apply to the empty list ?">
<msg 
  url="2009/01/a9e2313aff51e3555689baf7e4283478"
  from="Richard Jones &lt;rich@a...&gt;"
  author="Richard Jones"
  date="2009-01-10T12:59:36"
  subject="Re: [Caml-list] Why does value restriction not apply to the empty list ?">
<msg 
  url="2009/01/f244a598c38ac31f2efdb5190bcc1764"
  from="Arnaud Spiwack &lt;Arnaud.Spiwack@l...&gt;"
  author="Arnaud Spiwack"
  date="2009-01-10T13:10:39"
  subject="Re: [Caml-list] Why does value restriction not apply to the empty list ?">
</msg>
</msg>
<msg 
  url="2009/01/455d25be895d8c744758490fd4f28a1f"
  from="Antoine Delignat-Lavaud &lt;antoine.delignat-lavaud@d...&gt;"
  author="Antoine Delignat-Lavaud"
  date="2009-01-10T17:48:51"
  subject="Re: [Caml-list] Why does value restriction not apply to the empty list ?">
</msg>
<msg 
  url="2009/01/26c5a06033dc1589398fce69582e3431"
  from="Xavier Leroy &lt;Xavier.Leroy@i...&gt;"
  author="Xavier Leroy"
  date="2009-01-11T16:32:04"
  subject="Re: [Caml-list] Why does value restriction not apply to the empty list ?">
</msg>
</msg>
</thread>

<contents>
Antoine Delignat-Lavaud wrote:

&gt; I chose to solve the problem of polymorphic references by adding value
&gt; restriction* to my inferer, using ocaml to check my results.
&gt; Not knowing whether the empty list should be considered a value or an
&gt; expression, I copied Ocaml's behavior and made it a value.

Yes, the empty list is a value, like all other constants.

&gt; As a result, my inferer gave the following expression the integer type :
&gt; let el = [] in if hd el then 1 else hd el ;;
&gt; which is the expected result since el has polymorphic type 'a list
&gt; but does not look right because it is used as both a bool list and an
&gt; int list.

It is perfectly right.  The empty list can of course be used both as a
bool list and an int list; that's exactly what parametric polymorphism
is all about.

Richard Jones wrote:

&gt; But the same if statement within a function definition causes an error:
&gt;
&gt; # let f el =            
&gt;   if List.length el &gt; 0 then (List.hd el)+(int_of_string (List.hd el)) else 0;;
&gt;                                                           ^^^^^^^^^^
&gt; This expression has type int but is here used with type string

This is Hindley-Milner polymorphism at work: only "let"-bound
variables can have polymorphic types, while function parameters are
monomorphic.

- Xavier Leroy

</contents>

</message>

