From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA27319; Wed, 5 Nov 2003 11:03:52 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id LAA27079 for ; Wed, 5 Nov 2003 11:03:51 +0100 (MET) Received: from pop9.ucdavis.edu (pop9.ucdavis.edu [169.237.105.19]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id hA5A3n113233 for ; Wed, 5 Nov 2003 11:03:49 +0100 (MET) Received: from beech (beech.ucdavis.edu [128.120.141.134]) by pop9.ucdavis.edu (8.12.9/8.12.9/it-std-5.0.2) with ESMTP id hA5A3mEV012759 for ; Wed, 5 Nov 2003 02:03:48 -0800 (PST) Received: from ijtrotts by beech with local (Exim 3.36 #1 (Debian)) id 1AHKev-0007Tb-00 for ; Wed, 05 Nov 2003 02:13:05 -0800 Date: Wed, 5 Nov 2003 02:13:05 -0800 From: Issac Trotts To: caml-list@inria.fr Subject: Re: [Caml-list] function overloading Message-ID: <20031105101305.GA28600@ucdavis.edu> Reply-To: ijtrotts@ucdavis.edu References: <0F0B3332-0F6E-11D8-85C9-000393CFE6B8@spy.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0F0B3332-0F6E-11D8-85C9-000393CFE6B8@spy.net> User-Agent: Mutt/1.5.4i X-Loop: caml-list@inria.fr X-Spam: no; 0.00; issac:01 trotts:01 ijtrotts:01 caml-list:01 issac:01 trotts:01 bool:01 bool:01 05,:01 overloading:01 int:01 int:01 nov:01 match:02 match:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Wed, Nov 05, 2003 at 12:57:18AM -0800, Dustin Sallings wrote: > > I swear I found an example demonstrating how to do pattern matching > based on the type of an argument, but every pattern matching example I > can find now seems to be focused on value and not type. > > I'm trying to do something like this: > > let print_poly x = match x with > | (x: bool) -> print_bool x > | (x: int) -> print_int x > ;; > > Can someone tell me what I'm doing wrong (or perhaps tell me why I > 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 -> print_bool b | Int i -> 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