From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 69D40820A1 for ; Thu, 5 Sep 2013 19:31:00 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of john@coherentgraphics.co.uk) identity=pra; client-ip=188.64.184.40; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="john@coherentgraphics.co.uk"; x-sender="john@coherentgraphics.co.uk"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of john@coherentgraphics.co.uk) identity=mailfrom; client-ip=188.64.184.40; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="john@coherentgraphics.co.uk"; x-sender="john@coherentgraphics.co.uk"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@bluechip4.ukhost4u.com) identity=helo; client-ip=188.64.184.40; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="john@coherentgraphics.co.uk"; x-sender="postmaster@bluechip4.ukhost4u.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgoCALG+KFK8QLgoemdsb2JhbABbgzzCG4ErFg4BAQsHDQk8giQBAQUnEUABEAsHEQkTAw8JAwIBAgFFBg6IC7o/jy0zB4QdA6x8 X-IPAS-Result: AgoCALG+KFK8QLgoemdsb2JhbABbgzzCG4ErFg4BAQsHDQk8giQBAQUnEUABEAsHEQkTAw8JAwIBAgFFBg6IC7o/jy0zB4QdA6x8 X-IronPort-AV: E=Sophos;i="4.90,848,1371074400"; d="scan'208";a="31677896" Received: from bluechip4.ukhost4u.com ([188.64.184.40]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 05 Sep 2013 19:30:59 +0200 Received: from 78-105-203-81.zone3.bethere.co.uk ([78.105.203.81]:64848 helo=feast.local) by bluechip4.ukhost4u.com with esmtpa (Exim 4.80.1) (envelope-from ) id 1VHdOU-004HWH-Sa; Thu, 05 Sep 2013 18:30:58 +0100 Message-ID: <5228BFD0.2020608@coherentgraphics.co.uk> Date: Thu, 05 Sep 2013 18:30:56 +0100 From: John Whitington User-Agent: Postbox 3.0.8 (Macintosh/20130427) MIME-Version: 1.0 To: Casey Basichis CC: OCaml Mailing List References: <5228B581.3010903@coherentgraphics.co.uk> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bluechip4.ukhost4u.com X-AntiAbuse: Original Domain - inria.fr X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - coherentgraphics.co.uk X-Get-Message-Sender-Via: bluechip4.ukhost4u.com: authenticated_id: john@coherentgraphics.co.uk Subject: Re: [Caml-list] Construct a list of records from several lists 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/