From mboxrd@z Thu Jan 1 00:00:00 1970 X-Sympa-To: caml-list@inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id q0K8bMEK023499 for ; Fri, 20 Jan 2012 09:37:22 +0100 X-IronPort-AV: E=Sophos;i="4.71,541,1320620400"; d="scan'208";a="128186704" Received: from albireo.irisa.fr (HELO [131.254.14.27]) ([131.254.14.27]) by mail4-relais-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-CAMELLIA256-SHA; 20 Jan 2012 09:37:17 +0100 Message-ID: <4F1927BD.9040507@irisa.fr> Date: Fri, 20 Jan 2012 09:37:17 +0100 From: Sebastien Ferre Organization: IRISA User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100430 Fedora/3.0.4-2.fc12 Thunderbird/3.0.4 MIME-Version: 1.0 To: caml-list@inria.fr References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Validation-by: sebastien.ferre@irisa.fr Subject: Re: [Caml-list] is there a more concise way to write this? Hi, On 01/20/2012 07:46 AM, Valentin ROBERT wrote: > I guess you can write it like: > > let a = (if out then [o] else []) @ (if value then [v] else []) > > But it's not particularly more pleasant to the eye. > Still it reduces the exponential explosion of the code, at a small > additional cost (the @), I believe. You can make it even more concise by defining a helping function. let b2l b x = if b then [x] else [];; let a = b2l out o @ b2l value v;; This easily generalizes to an arbitrary number of boolean variables. --- Sébastien Ferré