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 MAA14037 for caml-redistribution; Fri, 9 Jun 1995 12:02:09 +0200 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.6.10/8.6.6) with ESMTP id CAA06004 for ; Fri, 9 Jun 1995 02:51:56 +0200 Received: from nisc.jvnc.net (nisc.jvnc.net [128.121.50.7]) by nez-perce.inria.fr (8.6.10/8.6.9) with ESMTP id CAA25010 for ; Fri, 9 Jun 1995 02:51:54 +0200 Received: from shaddam.usb.ve (shaddam.usb.ve [159.90.10.10]) by nisc.jvnc.net (8.6.4/8.6.4) with SMTP id UAA09978; Thu, 8 Jun 1995 20:51:32 -0400 Received: from usb.ve (yueh.usb.ve) by shaddam.usb.ve (4.1/USB-4.5.1) id AA02484; Thu, 8 Jun 95 19:10:14-040 Message-Id: <9506082310.AA02484@shaddam.usb.ve> To: U-E59264-Osman Buyukisik Cc: suarez@usb.ve, caml-list@pauillac.inria.fr Subject: Re: vector dot multiply In-Reply-To: Your message of "Thu, 08 Jun 1995 13:16:29 -0400." <199506081716.NAA01690@thomas.ge.com> Date: Thu, 08 Jun 1995 19:02:53 -0400 From: Ascander Suarez Sender: weis Concerning your second question: > ... > Also, is there a similar construct to Haskell array/list comprehensions? There is indeed one construct called streams. Ascander (suarez@usb.ve) ---------- streamExamples.ml ----------- (* A stream of natural numbers *) let rec generate f b = [< 'b; (generate f (f b)) >];; let nats = generate succ 0;; (* With this definition, the stream natS is the structure [< '0; '1; '2; ... >] *) (* A stream of Fibonacci numbers needs two generators and can be defined as: *) let rec generate2 f b1 b2 = [< 'b1; (generate2 f b2 (f b1 b2)) >];; let fibs = generate2 (prefix +) 1 1;; (* Finally, primes can be computed as follows: *) let rec filter n = function [< 'm; s >] -> if m mod n = 0 then filter n s else [< 'm; (filter n s) >];; let rec scieve = function [< 'm; s >] -> [< 'm; scieve(filter m s) >];; let primes = [< '1; scieve (generate succ 2) >];; (* Notice that streams in Caml light are a little bit surprising in that for any (big) stream s and any integer n, after let s' = (function [< 'x1; 'x2; ... 'xn; restOfStream >] -> restOfStream) s;; the streams s and s' are the same. *)