<?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/10/f3456671bdcf081d57adc3a920f0e8c4"
  from="Vincent Aravantinos &lt;vincent.aravantinos@g...&gt;"
  author="Vincent Aravantinos"
  date="2009-10-09T06:55:05"
  subject="Re: [Caml-list] Why type inference fails in this code"
  prev="2009/10/2f4e4d057ce5bb361d58ef7ac98d95e5"
  next="2009/10/c46218099f9f865f3799bc41a7795d00"
  prev-in-thread="2009/10/1b087dcc1f0f6132c02c68dbbb67bc95"
  next-in-thread="2009/10/c46218099f9f865f3799bc41a7795d00"
  prev-thread="2009/10/16051196b9d9c0d5bf42b865d44384e1"
  next-thread="2009/10/0880e1b35fd2d07cead92a1871df73b7"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="Why type inference fails in this code">
<msg 
  url="2009/10/1b087dcc1f0f6132c02c68dbbb67bc95"
  from="rouanvd@s..."
  author="rouanvd@s..."
  date="2009-10-09T06:16:12"
  subject="Why type inference fails in this code">
<msg 
  url="2009/10/f3456671bdcf081d57adc3a920f0e8c4"
  from="Vincent Aravantinos &lt;vincent.aravantinos@g...&gt;"
  author="Vincent Aravantinos"
  date="2009-10-09T06:55:05"
  subject="Re: [Caml-list] Why type inference fails in this code">
</msg>
<msg 
  url="2009/10/c46218099f9f865f3799bc41a7795d00"
  from="Gabriel Kerneis &lt;kerneis@p...&gt;"
  author="Gabriel Kerneis"
  date="2009-10-09T07:09:38"
  subject="Re: [Caml-list] Why type inference fails in this code">
<msg 
  url="2009/10/4ca654b611f32f152bdd91960b9dc571"
  from="Virgile Prevosto &lt;virgile.prevosto@m...&gt;"
  author="Virgile Prevosto"
  date="2009-10-09T08:22:27"
  subject="Re: [Caml-list] Why type inference fails in this code">
<msg 
  url="2009/10/5d9ee0d9aa8b4a42a068863184397ed1"
  from="Gabriel Kerneis &lt;kerneis@p...&gt;"
  author="Gabriel Kerneis"
  date="2009-10-09T08:41:38"
  subject="Re: [Caml-list] Why type inference fails in this code">
<msg 
  url="2009/10/5c96f1a40514c135879a94830d6a6998"
  from="Gabriel Kerneis &lt;kerneis@p...&gt;"
  author="Gabriel Kerneis"
  date="2009-10-09T08:59:17"
  subject="Re: [Caml-list] Why type inference fails in this code">
</msg>
</msg>
</msg>
</msg>
<msg 
  url="2009/10/9506deb4a1f605c5972917617848927b"
  from="Jeremy Yallop &lt;yallop@g...&gt;"
  author="Jeremy Yallop"
  date="2009-10-09T10:22:59"
  subject="Re: [Caml-list] Why type inference fails in this code">
</msg>
</msg>
</thread>

<contents>

Le 9 oct. 09 à 07:25, rouanvd@softwarerealisations.com a écrit :

&gt; ======================================================
&gt; type t = MyInt of int | MyFloat of float | MyString of string ;;
&gt;
&gt; let foo printerf = function
&gt;  | MyInt i -&gt; printerf string_of_int i
&gt;  | MyFloat x -&gt; printerf string_of_float x
&gt;  | MyString s -&gt; printerf (fun x -&gt; x) s
&gt; ;;
&gt; ======================================================


&gt; I read that there are lots of workarounds for the above code  
&gt; snippet, but
&gt; I would like to
&gt; Know why this code fails and what is the best workaround for this  
&gt; type of
&gt; code.

You might find some answers here:
http://caml.inria.fr/pub/old_caml_site/FAQ/FAQ_EXPERT-eng.html#arguments_polymorphes
Though this won't clearly tell you "why", and I sadly don't know the  
answer.

 From my experience the type system limitations are not so big  
hindrance in practice,
you may have to work a bit to get what you want fit in the type system,
but I've never found a thing that wouldn't work at all.

BTW:

&gt; I have done the same thing in Haskell and it correctly infers the  
&gt; type of
&gt; foo.

It doesn't work for me with ghc 6.10.3.
I mean, unless you provided the Haskell compiler with some type  
annotations the same error occurs.
But I am not a haskell expert so I may be wrong.

V.
</contents>

</message>

