Best way to dispatch on two arguments

From: Juan Jose Garcia Ripoll (
Date: Sat Jan 23 1999 - 15:18:33 MET

Date: Sat, 23 Jan 1999 15:18:33 +0100
From: Juan Jose Garcia Ripoll <>
To: Caml list <>
Subject: Best way to dispatch on two arguments


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

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?


This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:18 MET