Browse thread
Best way to dispatch on two arguments
- Juan Jose Garcia Ripoll
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Juan Jose Garcia Ripoll <jjgarcia@i...> |
| Subject: | Best way to dispatch on two arguments |
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