Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: [Caml-list] productivity improvement
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Alessandro Baretta <alex@b...>
Subject: Re: [Caml-list] productivity improvement


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.
> 
> <stdin>
> 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
> </stdin>
> 
> 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