Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Juan Jose Garcia Ripoll <jjgarcia@ind-cr.uclm.es>
To: Caml list <caml-list@pauillac.inria.fr>
Subject: Best way to dispatch on two arguments
Date: Sat, 23 Jan 1999 15:18:33 +0100	[thread overview]
Message-ID: <36A9DA39.8D7537A5@ind-cr.uclm.es> (raw)

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




                 reply	other threads:[~1999-01-24 14:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=36A9DA39.8D7537A5@ind-cr.uclm.es \
    --to=jjgarcia@ind-cr.uclm.es \
    --cc=caml-list@pauillac.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox