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 DAA24055; Sun, 14 Apr 2002 03:51:30 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id DAA18083 for ; Sun, 14 Apr 2002 03:51:29 +0200 (MET DST) Received: from favie.faith.gr.jp (favie.faith.gr.jp [61.127.175.250]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g3E1pKr22271 for ; Sun, 14 Apr 2002 03:51:27 +0200 (MET DST) Received: from localhost (dhcp7.faith.gr.jp [192.168.1.17]) by favie.faith.gr.jp (8.9.3/8.9.3) with ESMTP id KAA23458; Sun, 14 Apr 2002 10:51:06 +0900 To: georg.g@home.se Cc: ITrotts@IdolMinds.com, caml-list@inria.fr Subject: Re: [Caml-list] operator overloading In-Reply-To: <006201c1e333$1e3a2990$6f8f72d5@invariant.se> References: <5c4c7f87050f7f07d2@[192.168.1.6]> <006201c1e333$1e3a2990$6f8f72d5@invariant.se> X-Mailer: Mew version 1.94.2 on Emacs 20.7 / Mule 4.0 (HANANOEN) Mime-Version: 1.0 Content-Type: Text/Plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Message-Id: <20020414105045B.garrigue@kurims.kyoto-u.ac.jp> Date: Sun, 14 Apr 2002 10:50:45 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk From: Johan Georg Granstr=F6m > I had a way of working around lack of overloading, which is > actually pretty nice, when working with LISP a couple of years > ago. You simply define a macro which creates local bindings > for the arithmetic functions: then you can write for example [...] > let a =3D make_van_der_monde 3 > and b =3D make_matrix [|...|] in > matrix_arithmetic > (B + A) * (B - A) > = > By defining the proper macro (using camlp4 I guess), this would > expand to something like: > = > let a =3D make_van_der_monde 3 > and b =3D make_matrix [|...|] in > let (+) =3D (Matrix.+) > and (-) =3D (Matrix.-) > and (*) =3D (Matrix.*) in > (B + A) * (B - A) Note that if we had a let open ... in ... construct, you wouldn't even need camlp4 for that: let a =3D make_van_der_monde 3 and b =3D make_matrix [|...|] in let open Matrix in (b + a) * (b - a) By the way, this construct can already be simulated with camlp4. Note of course that this is not as powerful as overloading, since you often want to mix different instance of arithmetic operations in the same formula. Cheers, Jacques= ------------------- 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