<?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/11/57a8412c073003a82fda51c70c548daf"
  from="Issac Trotts &lt;ijtrotts@u...&gt;"
  author="Issac Trotts"
  date="2003-11-05T10:03:52"
  subject="Re: [Caml-list] function overloading"
  prev="2003/11/b23fea5c7f6cfe4c65fec96ce9078773"
  next="2003/11/51d232db64cdde1facee1368a5853bbc"
  prev-in-thread="2003/11/b23fea5c7f6cfe4c65fec96ce9078773"
  next-in-thread="2003/11/51d232db64cdde1facee1368a5853bbc"
  prev-thread="2003/11/7d1a89526a373d9c8ad55df4f4d4ad97"
  next-thread="2003/11/834f32c016ca6e13fe4db785db200a2d"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] function overloading">
<msg 
  url="2003/11/e00f3df02875aef67715de70b65c6100"
  from="Dustin Sallings &lt;dustin@s...&gt;"
  author="Dustin Sallings"
  date="2003-11-05T08:57:22"
  subject="[Caml-list] function overloading">
<msg 
  url="2003/11/b23fea5c7f6cfe4c65fec96ce9078773"
  from="Julien Demouth &lt;julien.demouth@f...&gt;"
  author="Julien Demouth"
  date="2003-11-05T09:46:21"
  subject="Re: [Caml-list] function overloading">
</msg>
<msg 
  url="2003/11/57a8412c073003a82fda51c70c548daf"
  from="Issac Trotts &lt;ijtrotts@u...&gt;"
  author="Issac Trotts"
  date="2003-11-05T10:03:52"
  subject="Re: [Caml-list] function overloading">
<msg 
  url="2003/11/51d232db64cdde1facee1368a5853bbc"
  from="Dustin Sallings &lt;dustin@s...&gt;"
  author="Dustin Sallings"
  date="2003-11-05T17:51:39"
  subject="Re: [Caml-list] function overloading">
</msg>
</msg>
<msg 
  url="2003/11/dce69ef2d7853d6760e22f2fdaaedce0"
  from="skaller &lt;skaller@o...&gt;"
  author="skaller"
  date="2003-11-07T08:06:35"
  subject="Re: [Caml-list] function overloading">
</msg>
</msg>
</thread>

<contents>
On Wed, Nov 05, 2003 at 12:57:18AM -0800, Dustin Sallings wrote:
&gt; 
&gt; 	I swear I found an example demonstrating how to do pattern matching 
&gt; based on the type of an argument, but every pattern matching example I 
&gt; can find now seems to be focused on value and not type.
&gt; 
&gt; 	I'm trying to do something like this:
&gt; 
&gt; let print_poly x = match x with
&gt;     | (x: bool) -&gt; print_bool x
&gt;     | (x: int) -&gt;  print_int x
&gt; ;;
&gt; 
&gt; 	Can someone tell me what I'm doing wrong (or perhaps tell me why I 
&gt; shouldn't be doing this at all)?

You can do this:

type bool_or_int = Bool of bool | Int of int;;

let print_bool b = print_string (if b then "true" else "false");;

let print_poly x = match x with 
    Bool b -&gt; print_bool b
  | Int i -&gt; print_int i;;

let x = Bool true;;

print_poly x;;

-- 
Issac Trotts

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

