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 MAA31050; Fri, 19 Jul 2002 12:36:32 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 MAA31046 for ; Fri, 19 Jul 2002 12:36:31 +0200 (MET DST) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from athlon.baretta.com (r-mi214-6a136.tin.it [62.211.4.136]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g6JAaU522628 for ; Fri, 19 Jul 2002 12:36:30 +0200 (MET DST) Received: from baretta.com (localhost.localdomain [127.0.0.1]) by athlon.baretta.com (Postfix) with ESMTP id 8B2E82724F; Fri, 19 Jul 2002 12:43:45 +0200 (CEST) Message-ID: <3D37ED61.40209@baretta.com> Date: Fri, 19 Jul 2002 12:43:45 +0200 From: Alessandro Baretta Organization: Baretta srl -- www.baretta.com User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0) Gecko/20020529 X-Accept-Language: it, en MIME-Version: 1.0 To: Oleg , ocaml Subject: Re: [Caml-list] productivity improvement References: <20020716172916.4903.qmail@web10702.mail.yahoo.com> <200207182313.TAA19905@dewberry.cc.columbia.edu> <20020719044206.GC29721@cs.brown.edu> <200207190956.FAA29574@dewberry.cc.columbia.edu> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Oleg wrote: > On Friday 19 July 2002 12:42 am, Emmanuel Renieris wrote: > >>I see two ways to weed through this list: >>Tell us what _you_ find hard/awkward/impossible in C++. Maybe somebody >>will be able to point out how they are easier in Ocaml (if indeed they >>are). > > > The first thing that comes to mind: a program that would read, write, listen, > look, speak, comprehend and pass the Turing test seems to be hard to create > in C++. So hard, I've never tried[1] I'm not sure if it's the language > though, although it could be. To think of it, I never tried running the hundred meter dash in 9.50s... Did anyone ever pass the Turing test anyway? >>Show us some of your ocaml code. Maybe there is some idiom you don't >>have yet, and that would make a difference. > > > Since this is the second time I'm asked, I will have to do that, even though > the program is really straight-forward, silly and uninstructive. Description > first, code at the end: Sometimes, when I feel like being organized and > productive[2], which happens no more than thrice per fortnight, I plan things > to do in advance and estimate time it will take me to do them: I edit a file > containing a list of tasks and time in minutes, e.g. > > > finish reading chapter 13 of ocaml book 30 > Determine Dr. Leroy's involvement in JFK assassination 180 > call dad 20 > have supper 20 > Go through T&R level in Halo in Legendary mode 30000 > > > The program reads it from STDIN, calculates completion times and formats > everything into a neat HTML table in STDOUT. I have a bash alias that glues > VIM, this program and browser together, of course. > > Oleg > > [1] I'm not kidding. It really is hard. > [2] And I actually am much more productive when I do that > > ------------------------------------------------------- > let print_aux hours minutes = > if hours < 10 then print_char ' '; > print_int hours; > print_char ':'; > if minutes < 10 then print_char '0'; > print_int minutes;; let print_aux h m = printf (if minutes < 10 then "%2d:0%1d" else "%2d:%2d") h m One line vs. 5 > let print_time m = > let m = m mod (60*24) in > let hours = m / 60 in > let hours = hours mod 24 in > let hours = if hours > 12 then hours - 12 else hours in > let tag = if m >= 12*60 then "pm" else "am" in > let minutes = m mod 60 in > print_aux hours minutes; > print_string tag;; let print_time m = print_aux (m mod 60) (m / (60*24) mod 12); print_string (if m mod (60*24) >= 12*60 then "pm" else "am") 3 vs. 8 If you continue to program more or less the same way you would in C you cannot notice any improvement. The language is functional. Don't think in terms of assignments. Don't redefine an identifier (hours). Use functions: apply them to expressions. You ought to think in terms of computations as opposed to operations. I have no more time now. Good bye. Alex ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners