caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Jonathan Roewen" <jonathan.roewen@gmail.com>
To: OCaml <caml-list@yquem.inria.fr>
Subject: [Caml-list] Feature Wish: List comprehensions
Date: Thu, 30 Mar 2006 20:38:23 +1200	[thread overview]
Message-ID: <ad8cfe7e0603300038l63485961y642b537250abdc6f@mail.gmail.com> (raw)

Hi,

I'm having a small problem trying to tidily define an equivalent
function to some Haskell code.

Haskell:
pThen combine p1 p2 toks
  = [ (combine v1 v2, toks2) | (v1,toks1) <- p1 toks, (v2, toks2) <- p2 toks1 ]

(I'll also be needing to specify equivalents for pThen3 & pThen4).

The first isn't too bad...

let pThen combine p1 p2 = fun ts ->
  let l1 = p1 ts in
  let l2 = List.map (fun (v1,ts1) -> p2 ts1) l1 in
  List.concat
    (List.map2 (fun (v1,ts1) l2 -> List.map (fun (v2,ts2) -> combine
v1 v2,ts2) l2) l1 l2)

As you can see, extending this style to pThen3 & pThen4 is going to be
very, very ugly (and hard to get right first time).

I know it's just shorthand for map/filter, (and more complex
derivatives of these), but it would be nice to have in ocaml...

BTW: any suggestions on a better way to write the above function would
be appreciated ;-)

Kindest Regards,

Jonathan Roewen


             reply	other threads:[~2006-03-30  8:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-30  8:38 Jonathan Roewen [this message]
2006-03-30 19:02 ` Martin Jambon

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=ad8cfe7e0603300038l63485961y642b537250abdc6f@mail.gmail.com \
    --to=jonathan.roewen@gmail.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).