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 XAA25574; Sat, 13 Apr 2002 23:35:50 +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 XAA25076 for ; Sat, 13 Apr 2002 23:35:49 +0200 (MET DST) Received: from smtp1.home.se (smtp1.home.se [195.66.35.200]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g3DLZmr20459 for ; Sat, 13 Apr 2002 23:35:49 +0200 (MET DST) Received: from seneca [213.114.143.111] by smtp1.home.se with Novonyx SMTP Server $Revision: 2.74 $; Sat, 13 Apr 2002 23:30:07 +0200 (ECTD) Message-ID: <006201c1e333$1e3a2990$6f8f72d5@invariant.se> From: =?iso-8859-1?Q?Johan_Georg_Granstr=F6m?= To: "Issac Trotts" Cc: References: <5c4c7f87050f7f07d2@[192.168.1.6]> Subject: Re: [Caml-list] operator overloading Date: Sat, 13 Apr 2002 23:35:23 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > Looking at the Google results, operator overloading has come up > as a frequently discuseed topic. Still I didn't find anything > very useful in the posts that Google brought up. Can anyone > recommend a way to work around OCaml's lack of operator overloading > when dealing with matrices, vectors, and spinors? Is there a > way to implement this with ocamlp4? 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 (make-van-der-monde 3)) (B (make-matrix '((4 2 1) (7 4 1) (8 5 2))))) (with-matrix-arithmetic (* (+ B A) (- B A)))) where make-van-der-monde and make-matrix are made up functions and with-matrix-arithmetic is the macro you define. In ocaml I guess this would become something like: let a = make_van_der_monde 3 and b = 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 = make_van_der_monde 3 and b = make_matrix [|...|] in let (+) = (Matrix.+) and (-) = (Matrix.-) and (*) = (Matrix.*) in (B + A) * (B - A) Similar macros could be defined for computation in whatever ring/field/group or whatever, you like... This is just an idea... Yours, - Johan Granström ------------------- 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