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 q0KL50Lj022673 for ; Fri, 20 Jan 2012 22:05:00 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhMBAKnWGU/AbSoIkWdsb2JhbABDhQSpBiIBAQEBCQsLBxQEIYFyAQEFIwRSEAsJBQwCJgICFBgxiBGnDZFTE4EciWEzYwSNVodCkk0 X-IronPort-AV: E=Sophos;i="4.71,544,1320620400"; d="scan'208";a="128292396" Received: from einhorn.in-berlin.de ([192.109.42.8]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 20 Jan 2012 22:04:32 +0100 X-Envelope-From: oliver@first.in-berlin.de Received: from first (e178003192.adsl.alicedsl.de [85.178.3.192]) (authenticated bits=0) by einhorn.in-berlin.de (8.13.6/8.13.6/Debian-1) with ESMTP id q0KL4Upn007664 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 20 Jan 2012 22:04:31 +0100 Received: by first (Postfix, from userid 1000) id C0266154036C; Fri, 20 Jan 2012 22:04:30 +0100 (CET) Date: Fri, 20 Jan 2012 22:04:30 +0100 From: oliver To: Edgar Friendly Cc: caml-list@inria.fr Message-ID: <20120120210430.GA2188@siouxsie> References: <20120120093834.GB1870@siouxsie> <4F197343.8070704@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <4F197343.8070704@gmail.com> User-Agent: Mutt/1.5.20 (2009-06-14) X-Scanned-By: MIMEDefang_at_IN-Berlin_e.V. on 192.109.42.8 Subject: Re: [Caml-list] is there a more concise way to write this? My fold approach version: let folded (out, value) o v = let a = if out then Some o else None in let b = if value then Some v else None in List.fold_left ( fun accum elem -> match elem with None -> accum | Some x -> x :: accum ) [] [ b; a ] or when following the way the other functions are notated (o and v not as parameters but in the environment) so that you can paste it into your code: let folded_env (out, value) = let a = if out then Some o else None in let b = if value then Some v else None in List.fold_left ( fun accum elem -> match elem with None -> accum | Some x -> x :: accum ) [] [ b; a ] If let ... = ... in let ... = ... in ... is slower than than let ... = ... and let ... = ... in ... then use the latter one ;-) Ciao, Oliver