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 q0KL9IuM023290 for ; Fri, 20 Jan 2012 22:09:18 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhMBAKnWGU/AbSoIkWdsb2JhbABDhQSpBiIBAQEBCQsLBxQEIYFyAQEFIwRSEAsJBQoCAiYCAhQYMYgRpw2RUxOBHIlhM2MEjVaHQpJN X-IronPort-AV: E=Sophos;i="4.71,544,1320620400"; d="scan'208";a="128292858" 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:09:15 +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 q0KL9En2007902 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 20 Jan 2012 22:09:14 +0100 Received: by first (Postfix, from userid 1000) id D310D154036C; Fri, 20 Jan 2012 22:09:13 +0100 (CET) Date: Fri, 20 Jan 2012 22:09:13 +0100 From: oliver To: Edgar Friendly Cc: caml-list@inria.fr Message-ID: <20120120210913.GA2310@siouxsie> References: <20120120093834.GB1870@siouxsie> <4F197343.8070704@gmail.com> <20120120210430.GA2188@siouxsie> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20120120210430.GA2188@siouxsie> 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? On Fri, Jan 20, 2012 at 10:04:30PM +0100, oliver wrote: > > 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 ... [...] meanI t: If let ... = ... in let ... = ... in ... is slower than than let ... = ... and ... = ... in ... of course. (copy & paste-related typo) Ciao, Oliver