caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
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 17:46:57 +0100	[thread overview]
Message-ID: <5228B581.3010903@coherentgraphics.co.uk> (raw)
In-Reply-To: <CAKX7ZAVuAmwXcX0wVNieBfMJPX9Xp-iFUOkewKDiL8UJOyaReg@mail.gmail.com>

Hi Casey,

Casey Basichis wrote:
> Hi,
>
> I'm new to Ocaml.

There is also this list, for beginners specifically:

http://groups.yahoo.com/neo/groups/ocaml_beginners/info

> I have five lists of ints, how can I can I combine them into a list of
> records where the fields are filled with values from each of the lists?

Do you mean that the lists are fixed-length, that you have a record type 
something like

type t = {a : int; b : int; c : int; d : int}

and you want to convert each list, which is something like

[1; 2; 3; 4]

into a record something like

{a = 1; b = 2; c = 3; d = 4}

?


In which case, you want to use pattern matching to write a function of type

int list -> t

which converts a (fixed-length) list to a thing of type t and then you 
can use List.map to deal with all your lists, producing a t list from an 
int list list.

If you meant something different entirely, please clarify!

With Thanks,

-- 
John Whitington
Director, Coherent Graphics Ltd
http://www.coherentpdf.com/


  reply	other threads:[~2013-09-05 16:47 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 [this message]
2013-09-05 17:15   ` Casey Basichis
2013-09-05 17:30     ` John Whitington

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=5228B581.3010903@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;
as well as URLs for NNTP newsgroup(s).