<?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/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 ?"
  prev="2009/01/9cb3439eed351c14973ea021f31f2a83"
  next="2009/01/f244a598c38ac31f2efdb5190bcc1764"
  prev-in-thread="2009/01/df2de1846d5559d3faa62662b822bba6"
  next-in-thread="2009/01/f244a598c38ac31f2efdb5190bcc1764"
  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>
On Sat, Jan 10, 2009 at 12:34:22PM +0100, Antoine Delignat-Lavaud wrote:
&gt; In Ocaml, the program
&gt; let el = [] in if List.length el &gt; 0 then (List.hd el)+(int_of_string 
&gt; (List.hd el)) else 0 ;;
&gt; yields not type error and returns 0 despite the use of el as both an int 
&gt; list and a string list.
&gt; 
&gt; Thus, I am wondering why does value restriction not apply to the empty 
&gt; list in Ocaml. I don't think it's possible to do a cast with the empty 
&gt; list (it is empty after all) but I don't see any benefit in doing so.

It's a strange one ... when the if statement appears as a toplevel
statement, OCaml infers the type 'a list for the list:

# let el = [] ;;
val el : 'a list = []
# if List.length el &gt; 0 then (List.hd el)+(int_of_string (List.hd el)) else 0;;
- : int = 0
# el ;;
- : 'a list = []

But the same if statement within a function definition causes an error:

# let f el =            
  if List.length el &gt; 0 then (List.hd el)+(int_of_string (List.hd el)) else 0;;
                                                          ^^^^^^^^^^
This expression has type int but is here used with type string

Rich.

-- 
Richard Jones
Red Hat

</contents>

</message>

