From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA01736; Mon, 9 Apr 2001 17:19:19 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA01731 for caml-list@pauillac.inria.fr; Mon, 9 Apr 2001 17:19:18 +0200 (MET DST) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id JAA20645 for ; Mon, 9 Apr 2001 09:29:38 +0200 (MET DST) Received: from localhost.localdomain (ppp41.dyn147.pacific.net.au [210.23.147.41]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f397TZf07568 for ; Mon, 9 Apr 2001 09:29:35 +0200 (MET DST) Received: from ozemail.com.au (IDENT:root@localhost [127.0.0.1]) by localhost.localdomain (8.9.3/8.8.7) with ESMTP id RAA01326; Mon, 9 Apr 2001 17:29:06 +1000 Message-ID: <3AD164C2.C1A4C5B2@ozemail.com.au> Date: Mon, 09 Apr 2001 17:29:06 +1000 From: John Max Skaller X-Mailer: Mozilla 4.7 [en] (X11; I; Linux 2.2.12-20 i686) X-Accept-Language: en MIME-Version: 1.0 To: Jacques Garrigue CC: patrick@watson.org, caml-list@inria.fr Subject: Re: [Caml-list] Future of labels, and ideas for library labelling References: <20010403093527G.garrigue@kurims.kyoto-u.ac.jp> <20010403125314Q.garrigue@kurims.kyoto-u.ac.jp> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Jacques Garrigue wrote: > > 1. List.fold_right (List.fold_right IntSet.add) lists IntSet.empty > > > > How can I use labels here without eta expansion? > > So, first let me see what your function is intending to do. > Ah, yes, your lists argument is a list of lists, and you want to put > everything into a set. > Now let's write it with labels > List.fold_left lists ~init:IntSet.empty > ~f:(fun set l -> > List.fold_left l ~init:set ~f:(fun set x -> IntSet.add x set)) > Note that I've switched to List.fold_left, which is tail recursive, > but you cannot do it with your approach. > I have also eta-expanded more than necessary, to make the code more > readable. > We can write something shorter if we use labels as they were in ocaml > 2.99, before their trimming: > List.fold_left lists ~acc:IntSet.empty > ~f:(List.fold_left ~f:(fun ~acc item -> IntSet.add acc ~item)) > Now, which is the more readable program, this one or yours. I'm a label mode supporter using classic mode exclusively. I have no problem reading the original expression. Both the label mode versions are harder for me to read due to a lot of extra clutter. However, were the example more complex, I think the label mode would win. More precisely: I didn't actually _read_ the original example: I mentally pattern-matched it in a single viewing. I had to scan the label mode versions multiple times. > Can you tell at first sight if this code is correct or not? No, but in this case, I think the label mode version is easier to check. I just 'guessed' what the classic mode version of the expression did, i didn't deduce it: its a common idiom I'm familiar with. > My experience, and that of Wolfram Kahl, is that the eta-expansions > you have to do when labels get in the way are more useful than > harmful. Hard to grasp at the beginning, but clearly there is good > verbosity and bad verbosity. Making the labels apparent is generally > good verbosity. My take is this: if it is possible to recognize something 'as a whole' in a compact form, the compact form is best. Otherwise, it is better to have enough redundancy that each part is easily connected with the others while scanning the parts. That is, classic mode is superior for simple things but doesn't scale. Here they are again, further reduced: fold_right (fold_right add) lists empty fold_left lists ~init:empty ~f:(fun set l -> fold_left l ~init:set ~f:(fun set x -> add x set)) The latter introduces extra names 'set' and 'l' and 'x', where 'set' has two distinct definitions, in addition to having the extra labels 'init' and 'f', which is 5 extra words. It also uses 4 twiddles and 4 colons (~:), and an extra pair of brackets, and takes three lines compared to one. I find the layout disturbing. I'd write: fold_left lists ~init:empty ~f: (fun set l -> fold_left l ~init:set ~f(fun set x -> add x set) ) which is 10 lines! Ugh. On the other hand, for a callback from a GUI function, the more longwinded style would probably help. -- John (Max) Skaller, mailto:skaller@maxtal.com.au 10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850 checkout Vyper http://Vyper.sourceforge.net download Interscript http://Interscript.sourceforge.net ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr