From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: weis Received: (from weis@localhost) by pauillac.inria.fr (8.6.10/8.6.6) id UAA01919 for caml-redistribution; Thu, 8 Jun 1995 20:29:53 +0200 Received: (from weis@localhost) by pauillac.inria.fr (8.6.10/8.6.6) id UAA01903; Thu, 8 Jun 1995 20:29:16 +0200 From: Pierre Weis Message-Id: <199506081829.UAA01903@pauillac.inria.fr> Subject: Re: vector dot multiply To: osman.buyukisik@ae.ge.com (U-E59264-Osman Buyukisik) Date: Thu, 8 Jun 1995 20:29:15 +0200 (MET DST) Cc: caml-list@pauillac.inria.fr In-Reply-To: <199506081716.NAA01690@thomas.ge.com> from "U-E59264-Osman Buyukisik" at Jun 8, 95 01:16:29 pm X-Mailer: ELM [version 2.4 PL21] Content-Type: text/plain Sender: weis > Hi, > What would be 1). elegant > 2). efficient > way to write a "dot multiply" function in caml-light? You're recursive version seems good (except that you (re)compute the vect_length of vector a at each recursive call). You may prefer an imperative version (as yours, this function assumes a and b to have the same length): let dot a b = let s = ref 0.0 in for i = 0 to vect_length a - 1 do s := a.(i) *. b.(i) +. !s done; !s;; > Also, is there a similar construct to Haskell array/list comprehensions? No. This is very difficult to get in a strict language, where these lists cannot be computed as necessary as is done in lazy languages... Pierre Weis ---------------------------------------------------------------------------- WWW Home Page: http://pauillac.inria.fr/~weis Projet Cristal INRIA, BP 105, F-78153 Le Chesnay Cedex (France) E-mail: Pierre.Weis@inria.fr Telephone: +33 1 39 63 55 98 Fax: +33 1 39 63 53 30 ----------------------------------------------------------------------------