<?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/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 ?"
  prev="2009/01/a9e2313aff51e3555689baf7e4283478"
  next="2009/01/7d3913d17469c862ee3e5ff3fceb4c1b"
  prev-in-thread="2009/01/a9e2313aff51e3555689baf7e4283478"
  next-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>

&gt; It's a strange one ... when the if statement appears as a toplevel
&gt; statement, OCaml infers the type 'a list for the list:
&gt;   
It is not anyhow strange, it is how OCaml always does. It generalises 
types of variables introduced by a let (or equivalently at toplevel), 
types of other variables are not polymorphic.

In the case of list it should be fairly clear, by the way, that the 
empty list is the only one that has type 'a list for all 'a.
&gt; # let el = [] ;;
&gt; val el : 'a list = []
&gt; # if List.length el &gt; 0 then (List.hd el)+(int_of_string (List.hd el)) else 0;;
&gt; - : int = 0
&gt; # el ;;
&gt; - : 'a list = []
&gt;
&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
&gt;
&gt; Rich.
&gt;
&gt;   

</contents>

</message>

