From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id q0KECTov009060 for ; Fri, 20 Jan 2012 15:12:33 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArcCAJd1GU9RZ90wlGdsb2JhbABDhQSoEmsiAQEBAQkLCQkUAyKBcgEBAQQjEVUCAQgOCgICBiACAgIwFRACBAEah3YGpm+RXwSBL4lhM2MElRmSSw X-IronPort-AV: E=Sophos;i="4.71,542,1320620400"; d="scan'208";a="140744379" Received: from mtaout02-winn.ispmail.ntl.com ([81.103.221.48]) by mail1-smtp-roc.national.inria.fr with ESMTP; 20 Jan 2012 15:12:32 +0100 Received: from aamtaout01-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout02-winn.ispmail.ntl.com (InterMail vM.7.08.04.00 201-2186-134-20080326) with ESMTP id <20120120141231.LGCA27245.mtaout02-winn.ispmail.ntl.com@aamtaout01-winn.ispmail.ntl.com>; Fri, 20 Jan 2012 14:12:31 +0000 Received: from romulus.metastack.com ([81.102.132.77]) by aamtaout01-winn.ispmail.ntl.com (InterMail vG.3.00.04.00 201-2196-133-20080908) with ESMTP id <20120120141231.ZZCK10211.aamtaout01-winn.ispmail.ntl.com@romulus.metastack.com>; Fri, 20 Jan 2012 14:12:31 +0000 Received: from remus.metastack.local ([172.16.0.1]) by romulus.metastack.com (8.14.2/8.14.2) with ESMTP id q0KECSlU027729 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=FAIL); Fri, 20 Jan 2012 14:12:28 GMT Received: from Remus.metastack.local ([fe80::547c:3c42:e1da:eda2]) by Remus.metastack.local ([fe80::547c:3c42:e1da:eda2%10]) with mapi id 14.01.0355.002; Fri, 20 Jan 2012 14:12:27 +0000 From: David Allsopp To: Edgar Friendly , "caml-list@inria.fr" Thread-Topic: [Caml-list] is there a more concise way to write this? Thread-Index: AQHM1z46do/3DbmtDEuU2RAHLw8lP5YU0B8AgAAaE6CAAFZMgIAAAjNg Date: Fri, 20 Jan 2012 14:12:27 +0000 Message-ID: References: <4F196C25.7070402@gmail.com> In-Reply-To: <4F196C25.7070402@gmail.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [212.183.128.50] Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Organization: MetaStack Solutions Ltd. X-Scanned-By: MIMEDefang 2.65 on 81.102.132.77 X-Cloudmark-Analysis: v=1.1 cv=JvdXmxIgLJv2/GthKqHpGJEEHukvLcvELVXUanXFreg= c=1 sm=0 a=p7R-vpKQdXMA:10 a=QlCY4dNUgAMA:10 a=cTs9vV391PwA:10 a=IkcTkHD0fZMA:10 a=xqWC_Br6kY4A:10 a=h6pNz4pCAAAA:8 a=W8rud-fVN6iJGdxewlUA:9 a=QEXdDO2ut3YA:10 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by walapai.inria.fr id q0KECTov009060 Subject: RE: [Caml-list] is there a more concise way to write this? Edgar Friendly wrote: > On 01/20/2012 03:37 AM, David Allsopp wrote: > > Actually, it's possible that with more cases it might be faster - it's > > eliminating the allocation (at some point) of all the tuples needed > > for the match case, > > Doesn't the ocaml compiler not allocate the unnecessary tuples? > https://ocaml.janestreet.com/?q=node/90 > > > it potentially eliminates a lot of linear comparisons to find the > > correct match case (I don't think that the compiler would be able to > > optimise that to a hash-based or index-based lookup) > > Isn't the compiler's compilation strategy for match cases able to build an > optimized tree of comparisons in cases like this? I agree there's no easy > index or hash strategy for this, but I'd expect it to turn this pattern > matching into the equivalent of: > > if a then if b then [a;b] else [a] > else if b then [b] else [] Maybe for this case with two variables, yes - but it can't do that indefinitely: as the number of variables increases, the code size increases exponentially. David