From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id PAA16892 for caml-redistribution; Sun, 24 Jan 1999 15:43:28 +0100 (MET) 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 PAA29849 for ; Sat, 23 Jan 1999 15:22:57 +0100 (MET) Received: from landsraad.net (caladan.arrakis.es [195.5.65.34]) by concorde.inria.fr (8.8.7/8.8.7) with ESMTP id PAA24427 for ; Sat, 23 Jan 1999 15:22:56 +0100 (MET) Received: from ind-cr.uclm.es (ib-6.arrakis.es [195.5.71.6]) by landsraad.net (8.9.2+/8.9.2) with ESMTP id PAA26051 for ; Sat, 23 Jan 1999 15:24:59 +0100 (MET) Sender: weis Message-ID: <36A9DA39.8D7537A5@ind-cr.uclm.es> Date: Sat, 23 Jan 1999 15:18:33 +0100 From: Juan Jose Garcia Ripoll X-Mailer: Mozilla 4.05 [en] (X11; I; Linux 2.0.34 i686) MIME-Version: 1.0 To: Caml list Subject: Best way to dispatch on two arguments Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hi, I'm trying to code a library of mathematical operations among matrices, vectors, polynoms, etc. I know OCaml does not have generic methods so now the question is what is the best way to dispatch on two arguments? I've thought of two possible implementations 1) Creating a single type of the form type = Matrix of ([int],float array) | Real of float |... and doing a large sequence of pattern matching. 2) Creating classes and defining one method for each binary operation. Now my questions are 3) When using (1) I would like to hide implementation issues without adding additional indirections. Thus, is it possible in OCaml to sum abstract types such as in type = matrix | real |... where Matrix, Real, etc, would be abstract types defined in separate modules? 4) Is (2) really possible? OCaml's methods are not polymorphic, so how should I code that binary operation method? What type should it be so that it admits any kind of mathemtical entity I define? Regards Juanjo