From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by sympa.inria.fr (Postfix) with ESMTPS id E12C87EC41 for ; Wed, 17 Oct 2012 00:14:17 +0200 (CEST) Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of kerneis@pps.jussieu.fr) identity=pra; client-ip=213.186.56.95; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="gabriel@kerneis.info"; x-sender="kerneis@pps.jussieu.fr"; x-conformance=sidf_compatible Received-SPF: Pass (mail4-smtp-sop.national.inria.fr: domain of gabriel@kerneis.info designates 213.186.56.95 as permitted sender) identity=mailfrom; client-ip=213.186.56.95; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="gabriel@kerneis.info"; x-sender="gabriel@kerneis.info"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: Pass (mail4-smtp-sop.national.inria.fr: domain of postmaster@witko.kerneis.info designates 213.186.56.95 as permitted sender) identity=helo; client-ip=213.186.56.95; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="gabriel@kerneis.info"; x-sender="postmaster@witko.kerneis.info"; x-conformance=sidf_compatible; x-record-type="v=spf1" X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqMNAAjcfVDVujhf/2dsb2JhbABFhSgjhhqzLASBAoEIgiABAQUnEwYBATcBDwsYHBIUKCGIG6dGhDMBBYEAjikGi084hgiVbYVXilyCYA8 X-IronPort-AV: E=Sophos;i="4.80,595,1344204000"; d="scan'208";a="159272519" Received: from witko.kerneis.info ([213.186.56.95]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/AES256-SHA; 17 Oct 2012 00:14:02 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kerneis.info; s=witko-rsa1; h=Subject:In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Cc:To:From:Date; bh=cM27hmnnLa9CaSad2oOI5kuyE5OicSxfZSpuEFNRUM8=; b=jkRA14x34MN6N86uIMbc/JbaHns1+OCkj/GT24U++DhLfaq8ZpJ/omAJ7WaIk230S106s/zWh8JlksWO/f91IUiM3jj2Zv9wtG+V2cE70GzVLFJmZrxy0CWqM9sZ8EHL; Received: from gabriel by witko.kerneis.info with local (Exim 4.72) (envelope-from ) id 1TOFOi-0004FJ-Pr; Wed, 17 Oct 2012 00:14:01 +0200 Date: Wed, 17 Oct 2012 00:14:00 +0200 From: Gabriel Kerneis To: William Cc: caml-list@inria.fr Message-ID: <20121016221400.GX26417@kerneis.info> References: <507DD785.8030300@libertysurf.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <507DD785.8030300@libertysurf.fr> User-Agent: Mutt/1.5.20 (2009-06-14) X-SA-Exim-Connect-IP: X-SA-Exim-Mail-From: gabriel@kerneis.info X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on witko.kerneis.info X-Spam-Level: X-SA-Exim-Version: 4.2.1 (built Mon, 22 Mar 2010 06:51:10 +0000) X-SA-Exim-Scanned: Yes (on witko.kerneis.info) Subject: Re: [Caml-list] caml match optimization On Tue, Oct 16, 2012 at 11:54:13PM +0200, William wrote: > let apply2 = function > | `Foo -> apply_all_elements foo foo_struct > | `Bar -> apply_all_elements bar bar_struct > | `Baz -> apply_all_elements baz baz_struct > [...] > | `Biz -> apply_all_elements biz biz_struct > > > How much is "apply2" inefficient ? Efficiency notwithstanding (and I wouldn't expect much of the OCaml compiler in this area), I'd find the code cleaner with a Map m from `Foo to (foo, foo_struct), `Bar to (bar, bar_struct), etc., then: let apply2 x = let (f,s) = Map.find x m in apply_all_elements f s Best, -- Gabriel