From: Casey Basichis <caseybasichis@gmail.com>
To: OCaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] Construct a list of records from several lists
Date: Thu, 5 Sep 2013 10:15:00 -0700 [thread overview]
Message-ID: <CAKX7ZAWEYAKCrgcy5-w6usH2B43Y2zNz2EoqiNC0BzGS_LN90Q@mail.gmail.com> (raw)
In-Reply-To: <5228B581.3010903@coherentgraphics.co.uk>
[-- Attachment #1: Type: text/plain, Size: 1794 bytes --]
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}
...
I will subscribe to the beginners list as well.
Thanks,
Casey
On Thu, Sep 5, 2013 at 9:46 AM, John Whitington <john@coherentgraphics.co.uk
> wrote:
> 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<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/
>
>
--
Casey James Basichis
Composer - Adventure Time - Cartoon Network
http://www.caseyjamesbasichis.com
caseybasichis@gmail.com
310.387.7540
[-- Attachment #2: Type: text/html, Size: 3886 bytes --]
next prev parent reply other threads:[~2013-09-05 17:15 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 [this message]
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=CAKX7ZAWEYAKCrgcy5-w6usH2B43Y2zNz2EoqiNC0BzGS_LN90Q@mail.gmail.com \
--to=caseybasichis@gmail.com \
--cc=caml-list@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