caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Ascander Suarez <suarez@usb.ve>
To: U-E59264-Osman Buyukisik <osman.buyukisik@ae.ge.com>
Cc: suarez@usb.ve, caml-list@pauillac.inria.fr
Subject: Re: vector dot multiply
Date: Thu, 08 Jun 1995 19:02:53 -0400	[thread overview]
Message-ID: <9506082310.AA02484@shaddam.usb.ve> (raw)
In-Reply-To: Your message of "Thu, 08 Jun 1995 13:16:29 -0400." <199506081716.NAA01690@thomas.ge.com>


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.

*)





  parent reply	other threads:[~1995-06-09 10:02 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1995-06-08 17:16 U-E59264-Osman Buyukisik
1995-06-08 18:29 ` Pierre Weis
1995-06-08 23:02 ` Ascander Suarez [this message]
1995-06-08 23:17 ` Bob Buckley
1995-06-09  7:29 ` Pascal Nicolas
1995-06-09 10:42   ` Judicael Courant
1995-06-09 11:50 Chet Murthy
1995-06-09 13:20 ` nikhil

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9506082310.AA02484@shaddam.usb.ve \
    --to=suarez@usb.ve \
    --cc=caml-list@pauillac.inria.fr \
    --cc=osman.buyukisik@ae.ge.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).