From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 83AB9BD74 for ; Tue, 16 Aug 2005 15:17:56 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j7GDHtYH021190 for ; Tue, 16 Aug 2005 15:17:56 +0200 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA05132 for ; Tue, 16 Aug 2005 15:17:55 +0200 (MET DST) Received: from smtp1.adl2.internode.on.net (smtp1.adl2.internode.on.net [203.16.214.181]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j7GDHrRN006117 for ; Tue, 16 Aug 2005 15:17:54 +0200 Received: from rosella (ppp20-154.lns2.syd7.internode.on.net [59.167.20.154]) by smtp1.adl2.internode.on.net (8.12.9/8.12.9) with ESMTP id j7GDHiEo035863; Tue, 16 Aug 2005 22:47:45 +0930 (CST) Subject: Re: [Caml-list] Snd question From: skaller To: Matt Gushee Cc: caml-list@inria.fr In-Reply-To: <43011A10.4090108@havenrock.com> References: <161F0D30A699A84A8B7435B62BCE33B30360E19F@APS-MSG-01.southpacific.corp.microsoft.com> <43011A10.4090108@havenrock.com> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-5lbpy9BGwsstOd4gLrxM" Date: Tue, 16 Aug 2005 23:17:44 +1000 Message-Id: <1124198264.13635.25.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.2.1.1 X-Miltered: at concorde with ID 4301E783.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 4301E781.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 anu:01 ocaml:01 indexing:01 endl:01 run-time:01 untyped:01 metaocaml:01 ...:98 wrote:01 wrote:01 sourceforge:01 sourceforge:01 compile:01 compile:01 X-Attachments: cset="utf-8" type="application/pgp-signature" name="signature.asc" X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 --=-5lbpy9BGwsstOd4gLrxM Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Mon, 2005-08-15 at 16:41 -0600, Matt Gushee wrote: > Anu Engineer wrote: >=20 > > Please forgive me if my question is very na=C3=AFve, I am very new to=20 > Ocaml. I was >=20 > > wondering why snd returns an error when I use it with more than 2=20 > elements, why >=20 > > not return the rest of the list when I apply to something larger than=20 > a pair ? >=20 >=20 > Your question shows your misunderstanding: snd operates on tuples, not=20 > lists.=20 I think the original question really meant: Why aren't "fst" and "snd" properly generic?? For example this simply *should* work: snd (1,2,3) and even pattern matching can't handle it: match e with (h,t,...) ->=20 also should work. Felix actually supports this ugly generic tuple projection operator: (1,2.1).(1) // generic n'th of tuple (1,2.1,3).(1) // n must be compile time constant and even: var i:int; for_each {i=3D0;} {i<3} {++i;} { print (1,2,3).[i]; // run time indexing endl; }; because a tuple of all the same type is an array, but as yet I haven't found a way to make ... work in=20 pattern matches.=20 It would actually be nice to have more general support for polyadic tuple management: for example thinking about obtaining a slice of a tuple, or concatenating two tuples, suggests that just getting the n'th component is special case. This kind of thing can actually be done in a hacky way within limits with C++ template meta-programming. A more general mapping from a list of types (at compile time) representing tuples should be possible: any list operation on types is a run-time operation on values. Unfortunately I doubt camlp4 can handle that, since it is dealing with untyped terms. Perhaps MetaOcaml can do it? I would love to do this in Felix .. but it requires dynamic loading. --=20 John Skaller --=-5lbpy9BGwsstOd4gLrxM Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (GNU/Linux) iD8DBQBDAed3sRp8/9aGVGsRAgm8AJ4sDMGfFxb4AgPfFDvlKzvHWZ2O9wCglGVn aoXhNiXaDejLduAA1thLjo4= =YUSf -----END PGP SIGNATURE----- --=-5lbpy9BGwsstOd4gLrxM--