<?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/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"
  prev="2003/12/c9409b63462d80cc0a4b0355adf1e0b0"
  next="2003/12/eac46552a7b577d9a89a07fc38092a70"
  next-in-thread="2003/12/eac46552a7b577d9a89a07fc38092a70"
  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>
Can anyone explain to me why the following doesn't compile:

----------

type thing = Int of int | String of string ;;

let int_of_thing t =
   match t with
       Int i -&gt; i
     | String s -&gt; int_of_string s ;;

let string_of_thing t =
   match t with
       Int i -&gt; string_of_int i
     | String s -&gt; s ;;

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

let is_less_than t1 t2 =
   compare_things t1 t2 (&lt;) ;;

let is_greater_than t1 t2 =
   compare_things t1 t2 (&gt;) ;;

----------

The compiler says:

File "test.ml", line 16, characters 38-39:
This expression has type string but is here used with type int

It seems to have decided that in the function compare_things, 
comparison_fun is int -&gt; int -&gt; 'a because that's how it's used in the 
first pattern, not realising that I mean to pass a polymorphic function, 
'a -&gt; 'a -&gt; bool.

Is there a way to make this work?  (Specifying the type of 
comparison_fun as 'a -&gt; 'a -&gt; bool makes no difference.)

Ben

-------------------
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>

