caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jon Harrop <jon@ffconsultancy.com>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] List comprehensions
Date: Sat, 18 Aug 2007 15:46:11 +0100	[thread overview]
Message-ID: <200708181546.11206.jon@ffconsultancy.com> (raw)
In-Reply-To: <34D0D539-54E0-4867-AA9F-5327683004E2@gmail.com>

On Saturday 18 August 2007 15:44:04 Joel wrote:
> On Aug 18, 2007, at 3:28 PM, Jon Harrop wrote:
> > # [x + 2*x + x/2 | x <- [1; 2; 3; 4]];;
> > - : int list = [3; 7; 10; 14]
>
> How do you do something like this?
>
> [x + 2*x + y/2 | x <- [1; 2; 3; 4], [y <- [3; 4; 5]];;
>
> That is a list comprehension with more than one variable where all
> variables come from lists.

Ooh, look:

# let rec sort = function
    | [] -> []
    | x::xs -> sort [y | y <- xs; y<x] @ [x] @ sort [y | y <- xs; y>=x];;
val sort : 'a list -> 'a list = <fun>
# sort [3;1;6;2;7;4;9;8];;
- : int list = [1; 2; 3; 4; 6; 7; 8; 9]

Hmm, maybe we could form some sort of rudimentary lathe...

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
OCaml for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists/?e


  reply	other threads:[~2007-08-18 14:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-18 14:28 Jon Harrop
2007-08-18 14:44 ` [Caml-list] " Joel Reymont
2007-08-18 14:46   ` Jon Harrop [this message]
2007-08-19 10:26   ` Nicolas Pouillard
2007-08-18 14:54 ` skaller
2007-08-20 22:55   ` Nathaniel Gray
2007-08-22  8:54     ` Adrien

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=200708181546.11206.jon@ffconsultancy.com \
    --to=jon@ffconsultancy.com \
    --cc=caml-list@yquem.inria.fr \
    /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).