Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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: 2002-07-19 (09:56)
From: Oleg <oleg_inconnu@m...>
Subject: Re: [Caml-list] productivity improvement
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.

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


[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_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_duration m =
    let hours = m / 60 in
    let hours = hours mod 24 in
    let minutes = m mod 60 in
    print_aux hours minutes;;

let curr_time = 
    let tmp = Unix.localtime (Unix.time ()) in
    tmp.Unix.tm_min + 60 * tmp.Unix.tm_hour;;

let isdigit = function '0' | '1' .. '9' -> true | _ -> false;;

let split_string s = 
    let i = ref (String.length s - 1) in
    while !i >= 0 && (s.[!i] = ' ' || s.[!i] = '\t') do i := !i-1 done;
    while (!i >= 0) && (isdigit (s.[!i])) do i := !i-1 done;
    i := !i+1;
    String.sub s 0 !i, int_of_string (String.sub s !i (String.length s - 

let print_table_entry name duration curr_time = 
    print_string ("\t<tr><td align=left>" ^ name ^ "</td><td align=right>");
    print_duration duration;
    print_string "</td><td align=right>";
    print_time (curr_time + duration);
    print_string "</td></tr>\n";;

print_string "<html>
<title> Schedule </title>
<body bgcolor=\"#773333\" text=\"#00ff00\">
<table border=\"2\">\n";;

let rec read_and_print curr_time =
    let s = input_line stdin in
    let (s, v) = split_string s in
    print_table_entry s v curr_time;
    read_and_print (curr_time + v) 
in try
    read_and_print curr_time
    _ -> ();;

print_string "</table>
To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: