<?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="2003/12/22a7ccbbbae6a7e18cdc45f3ea6dabc4"
  from="Olivier Andrieu &lt;andrieu@i...&gt;"
  author="Olivier Andrieu"
  date="2003-12-14T22:06:18"
  subject="Re: [Caml-list] polymorphic function not recognised as such"
  prev="2003/12/1380e77c5d5f6a5e2966de692bdc968a"
  next="2003/12/0a43e811112e9d2e886447b4a4cde60d"
  prev-in-thread="2003/12/1380e77c5d5f6a5e2966de692bdc968a"
  next-in-thread="2003/12/af83cb0ff0838dd0dc048fae73cb32e2"
  prev-thread="2003/12/c9409b63462d80cc0a4b0355adf1e0b0"
  next-thread="2003/12/2539c2c91c0d6a1135376d2e330ca702"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] polymorphic function not recognised as such">
<msg 
  url="2003/12/4254f003f0a5d186c5e7a8b31e551054"
  from="Benjamin Geer &lt;ben@s...&gt;"
  author="Benjamin Geer"
  date="2003-12-14T19:14:17"
  subject="[Caml-list] polymorphic function not recognised as such">
<msg 
  url="2003/12/eac46552a7b577d9a89a07fc38092a70"
  from="Jean-Baptiste Rouquier &lt;jean-baptiste.rouquier@e...&gt;"
  author="Jean-Baptiste Rouquier"
  date="2003-12-14T20:06:35"
  subject="Re: [Caml-list] polymorphic function not recognised as such">
</msg>
<msg 
  url="2003/12/1380e77c5d5f6a5e2966de692bdc968a"
  from="Benjamin Geer &lt;ben@s...&gt;"
  author="Benjamin Geer"
  date="2003-12-14T21:38:31"
  subject="Re: [Caml-list] polymorphic function not recognised as such">
<msg 
  url="2003/12/22a7ccbbbae6a7e18cdc45f3ea6dabc4"
  from="Olivier Andrieu &lt;andrieu@i...&gt;"
  author="Olivier Andrieu"
  date="2003-12-14T22:06:18"
  subject="Re: [Caml-list] polymorphic function not recognised as such">
</msg>
<msg 
  url="2003/12/af83cb0ff0838dd0dc048fae73cb32e2"
  from="Michal Moskal &lt;malekith@p...&gt;"
  author="Michal Moskal"
  date="2003-12-15T12:11:02"
  subject="Re: [Caml-list] polymorphic function not recognised as such">
</msg>
</msg>
</msg>
</thread>

<contents>
 Benjamin Geer [Sunday 14 December 2003] :
 &gt;
 &gt; Jean-Baptiste Rouquier wrote:
 &gt; &gt;    compare_things : thing -&gt; thing -&gt; ('a -&gt; 'a -&gt; bool) -&gt; bool
 &gt; &gt; doesn't mean that comparison_fun has to be polymorphic, but it means 
 &gt; &gt; that any function with type ('a -&gt; 'a -&gt; bool), where 'a is any type, is 
 &gt; &gt; acceptable. For instance, the type checker would accept a function of 
 &gt; &gt; the type (char -&gt; char -&gt; bool).
 &gt; 
 &gt; OK, but it seems that the type checker has inferred the type of
 &gt; comparison_fun just by looking at its first use in compare_things,
 &gt; and has decided that it must be monomorphic; this is an incorrect
 &gt; inference.
 &gt;   My naive impression is that if the type checker was willing to
 &gt; accept both uses of comparison_fun as valid (or perhaps if it also
 &gt; looked at the places where compare_things is called), it would
 &gt; conclude that comparison_fun does indeed have to be polymorphic.
 &gt; In that case, I would get a compile error if I tried to pass a
 &gt; non-polymorphic function to compare_things.  Would this be this
 &gt; asking too much?  (I suspect the answer is yes; I'm just
 &gt; curious...)

You could use a record holding a field with a fully polymorphic type : 

type t = { c : 'a. 'a -&gt; 'a -&gt; bool }

let compare_things t1 t2 comparison_fun =
   match (t1, t2) with
       (Int i, _) -&gt; comparison_fun.c i (int_of_thing t2)
     | (String s, _) -&gt; comparison_fun.c s (string_of_thing t2) ;;

-- 
   Olivier

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners

</contents>

</message>

