From mboxrd@z Thu Jan 1 00:00:00 1970 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 q0K9CLW1025511 for ; Fri, 20 Jan 2012 10:12:25 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkIBAAIvGU+GnQCBgGdsb2JhbABDrXsiAQEJDQsFFgMigXIBAQU6PxALGC4UScEGi0NjBJUXkk0 X-IronPort-AV: E=Sophos;i="4.71,541,1320620400"; d="scan'208";a="128192460" Received: from shiva.jussieu.fr ([134.157.0.129]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 20 Jan 2012 10:12:24 +0100 Received: from hydrogene.pps.jussieu.fr (hydrogene.pps.jussieu.fr [134.157.168.1]) by shiva.jussieu.fr (8.14.4/jtpda-5.4) with ESMTP id q0K9Bqii091757 ; Fri, 20 Jan 2012 10:12:05 +0100 (CET) X-Ids: 165 Received: from strontium.pps.jussieu.fr (strontium.pps.jussieu.fr [134.157.168.38]) by hydrogene.pps.jussieu.fr (Postfix) with ESMTPS id 6B239C0B42; Fri, 20 Jan 2012 10:11:51 +0100 (CET) Received: from vouillon by strontium.pps.jussieu.fr with local (Exim 4.77) (envelope-from ) id 1RoAVj-0003bB-AB; Fri, 20 Jan 2012 10:11:51 +0100 Date: Fri, 20 Jan 2012 10:11:51 +0100 From: Jerome Vouillon To: Sebastien Ferre Cc: caml-list@inria.fr Message-ID: <20120120091151.GA13799@pps.jussieu.fr> References: <4F1927BD.9040507@irisa.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4F1927BD.9040507@irisa.fr> User-Agent: Mutt/1.5.21 (2010-09-15) X-Miltered: at jchkmail.jussieu.fr with ID 4F192FD8.002 by Joe's j-chkmail (http : // j-chkmail dot ensmp dot fr)! X-j-chkmail-Enveloppe: 4F192FD8.002/134.157.168.1/hydrogene.pps.jussieu.fr/hydrogene.pps.jussieu.fr/ Subject: Re: [Caml-list] is there a more concise way to write this? On Fri, Jan 20, 2012 at 09:37:17AM +0100, Sebastien Ferre wrote: > 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;; You can also include the list concatenation in the helper function: let maybe b v c = if b then v :: c else c let g out o value v = maybe out o (maybe value v []) And the parentheses can be avoided by using a right associative application operator: let (@@) f x = f x let a = maybe out o @@ maybe value v @@ [] -- Jerome