Re: vector dot multiply
 Pierre Weis
[
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:  Pierre Weis <weis@p...> 
Subject:  Re: vector dot multiply 
> Hi, > What would be 1). elegant > 2). efficient > way to write a "dot multiply" function in camllight? 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, F78153 Le Chesnay Cedex (France) Email: Pierre.Weis@inria.fr Telephone: +33 1 39 63 55 98 Fax: +33 1 39 63 53 30 