From: John Whitington <john@coherentgraphics.co.uk>
To: Casey Basichis <caseybasichis@gmail.com>
Cc: OCaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] Construct a list of records from several lists
Date: Thu, 05 Sep 2013 18:30:56 +0100 [thread overview]
Message-ID: <5228BFD0.2020608@coherentgraphics.co.uk> (raw)
In-Reply-To: <CAKX7ZAWEYAKCrgcy5-w6usH2B43Y2zNz2EoqiNC0BzGS_LN90Q@mail.gmail.com>
Hi,
Casey Basichis wrote:
>
> Sorry about the confusion. I'm taking from one element from each list
> per record. The lists can all be arbitrarily long as long as they share
> the same length.
>
> lista = [1; 2; 3; 4; 5; 6; 3]
> listb = [2; 5; 7; 8; 1; 2; 4]
> listc = [4; 6; 8; 3; 5; 8; 2]
>
> type t = {a : int; b: int; c: int}
>
> {a=1; b=2; c=4}
> {a=2; b=5; c=6}
> {a=3; b=7; c=8}
> {a=4; b=8; c=3}
So with
type t = {a : int; b : int; c : int}
So you want a function of type
int list -> int list -> int list -> t list
I left a few blanks (* ... *) for you to fill in:
let build_record p q r =
(* Put something here to build a single record *)
let rec records_from_lists la lb lc =
match la, lb, lc with
| [], [], [] ->
(* And something here to deal with the base case *)
| x::xs, y::ys, z::zs ->
build_record x y z :: records_from_lists xs ys zs
| _ ->
(* And something here to deal with malformed inputs *)
If you need any more help, I suggest we move it to the beginners list...
With Thanks,
--
John Whitington
Director, Coherent Graphics Ltd
http://www.coherentpdf.com/
prev parent reply other threads:[~2013-09-05 17:31 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-05 16:38 Casey Basichis
2013-09-05 16:46 ` John Whitington
2013-09-05 17:15 ` Casey Basichis
2013-09-05 17:30 ` John Whitington [this message]
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=5228BFD0.2020608@coherentgraphics.co.uk \
--to=john@coherentgraphics.co.uk \
--cc=caml-list@inria.fr \
--cc=caseybasichis@gmail.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