From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id q0K9cge6027247 for ; Fri, 20 Jan 2012 10:38:42 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkMCAOY0GU/AbSoIe2dsb2JhbABDhQSodyIBARYmBCGBcgEBBSMEUhALCQ8CAiYCAhQYMYgRpxqRZhOBHIlhM2MEjVWHQpJN X-IronPort-AV: E=Sophos;i="4.71,541,1320620400"; d="scan'208";a="140693925" Received: from einhorn.in-berlin.de ([192.109.42.8]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 20 Jan 2012 10:38:36 +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 q0K9cZ8f012927 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 20 Jan 2012 10:38:35 +0100 Received: by first (Postfix, from userid 1000) id DD422154036C; Fri, 20 Jan 2012 10:38:34 +0100 (CET) Date: Fri, 20 Jan 2012 10:38:34 +0100 From: oliver To: Martin DeMello Cc: OCaml List Message-ID: <20120120093834.GB1870@siouxsie> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: 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? Hello, On Thu, Jan 19, 2012 at 10:38:53PM -0800, Martin DeMello wrote: > let a = match (out, value) with > (true, true) -> [o; v] > | (false, true) -> [v] > | (true, false) -> [o] > | (false, false) -> [] The code looks fine for me. More concise does not always mean better readable or more performant. You apply the same kind of selection for both values. Something that would aequivalent would be of type 'a option. But I doubt that using option type here would make it more concise. Would it make it Better readable? Not necessarily. But at least it would show the operation more clear. But not sure if you want to handle option type in your result. I think a fold could do the selection of the raw values afterwards. If out is derived from o and v is derived from v and both are selected by the same function, you could use that function inside a fold. But would that really be more readable? It might be more generic. But if both selections are not done by the same function application to your result values, this also does not make sense. Do you see what I mean? Ciao, Oliver