From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 3C1A5BB84 for ; Wed, 13 Aug 2008 13:29:42 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgABAC1iokjC2fJXo2dsb2JhbACJMYhFAQEBAQEBBwUIBxGlAYFV X-IronPort-AV: E=Sophos;i="4.32,201,1217800800"; d="scan'208";a="15964014" Received: from anchor-post-37.mail.demon.net ([194.217.242.87]) by mail3-smtp-sop.national.inria.fr with ESMTP; 13 Aug 2008 13:29:41 +0200 Received: from orion.metastack.com ([80.177.38.218]) by anchor-post-37.mail.demon.net with esmtp (Exim 4.69) id 1KTEXs-0007Kz-OL for caml-list@yquem.inria.fr; Wed, 13 Aug 2008 11:29:40 +0000 Received: from orion.metastack.com (IDENT:25@localhost [127.0.0.1]) by orion.metastack.com (8.13.4/8.13.3) with ESMTP id m7DB9OPZ013393 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 13 Aug 2008 12:10:43 +0100 Received: (from defang@localhost) by orion.metastack.com (8.13.4/8.13.3/Submit) id m7DAjoc6013315 for ; Wed, 13 Aug 2008 11:45:50 +0100 X-Authentication-Warning: orion.metastack.com: defang set sender to using -f Received: from countertenor (cpc1-cmbg10-0-0-cust76.cmbg.cable.ntl.com [81.102.132.77]) by orion.metastack.com (envelope-sender ) (MIMEDefang) with ESMTP id m7DAjjrE013309; Wed, 13 Aug 2008 11:45:50 +0100 (BST) From: "David Allsopp" To: "'Brighten Godfrey'" Cc: "'OCaml List'" References: <9E2C98C8798A487DAE77F20A9DC4F1E8@countertenor> <7C6C7ADD-910D-4C62-92FF-E286F0817FA1@cs.berkeley.edu> <1C96BA4C-8E65-44AA-96CD-C1CA399635E2@cs.berkeley.edu> Subject: RE: [Caml-list] Value shadowing (tangent) Date: Wed, 13 Aug 2008 12:04:26 +0100 Organization: MetaStack Solutions Ltd. Message-ID: <583C0D4BF86A484BACB5D503F09037F1@countertenor> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 11 Thread-Index: Acj9L67rCQK9+WMXQJ23spACifjAUgAAyGPA X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512 In-Reply-To: <1C96BA4C-8E65-44AA-96CD-C1CA399635E2@cs.berkeley.edu> X-Scanned-By: MIMEDefang 2.63 on 80.177.38.218 X-Spam: no; 0.00; ocaml:01 ocaml:01 compiler:01 implements:01 readable:01 compile:01 caml-list:01 let:03 let:03 indentation:04 scope:04 nested:04 invaluable:92 indeed:07 written:07 > Going off on a tangent here... Indeed :o) > > let lst = [5; 4; 3; 2; 1; 0; -1; -2; -3; -4; -5] > > in > > let filter = List.filter (fun x -> x > 0) > > in > > let double = List.map (fun x -> -2 * x) > > in > > let sort = List.sort compare > > in > > (sort $$ double $$ filter) lst > > I've seen little of other people's OCaml code, so out of curiosity, > do you or others actually write code formatted like the above, as > opposed to the more compact and (I think) readable > > let lst = [5; 4; 3; 2; 1; 0; -1; -2; -3; -4; -5] in > let filter = List.filter (fun x -> x > 0) in > let double = List.map (fun x -> -2 * x) in > let sort = List.sort compare in > (sort $$ double $$ filter) lst I similarly learned OCaml without reference to anyone else's code - I find the indentation invaluable when reading the code for spotting the scope. I would normally have written the above as let lst = [5; 4; 3; 2; 1; 0; -1; -2; -3; -4; -5] and filter = List.filter (fun x -> x > 0) and double = List.map (fun x -> -2 * x) and sort = List.sort compare in (sort $$ double $$ filter) lst Which is actually less to type than yours but I was adapting the previous let lst = .. let lst = .. which is why I ended up with a very indented version in my previous post. I've not seen it anywhere else but then I haven't looked! I don't know how the OCaml compiler actually implements displays, but the "quick" approach means that using let .. and .. in instead of nested lets will compile faster as name resolution will be faster :o) David