Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* RE: Imperative programming in Caml
@ 2000-08-04 18:33 Don Syme
  2000-08-04 19:48 ` Walid Taha
  0 siblings, 1 reply; 11+ messages in thread
From: Don Syme @ 2000-08-04 18:33 UTC (permalink / raw)
  To: 'Walid Taha', caml-list


I don't know how it fits with the grammar, but something like
  mutable finished = false 
  mutable list = Empty
  mutable here = list 

might make things a bit clearer.  You could have implicit dereferencing for
everything declared with "mutable" and something like C's "&finished" if you
wanted to pass the reference.

Just a thought,
Don



-----Original Message-----
From: Walid Taha [mailto:taha@cs.chalmers.se]
Sent: 03 August 2000 20:20
To: caml-list@inria.fr
Subject: Imperative programming in Caml



[Apologies in advance for purists that this project might offend.]

Dear all,

Below is one of my first attempts at imperative programming in ML: a
program that reads a list of numbers and squares them, using a "mutable
list".  The presence of a "while" construct and easy of terminal IO in
Caml should help an imperative programmer feel at home.  But I am
concerned (and a bit surprised, actually) that the use of "let" bindings
and the presence of normal variables in addition to "mutable" variables
might make it more difficult to explain this program to a beginer that is
*not* interested in the functional aspects.  If any one has suggestions
for making this program more "imperative", I would appreciate it.

Many thanks in advance,

Walid.

---

let squareMany () =
 print_string "\nPlease enter zero (0) to stop.\n\n"; 
 let finished = ref false 
 and list = ref Empty in 
 let here = ref list in
 while not(!finished) do
        print_string "Enter a number : ";
        let number = read_int () in
        if number<>0 
         then begin
               let new = ref Empty in
               !here := Cell (number, new);
               here := new;
              end
         else begin
               finished:=true;
              end 
       done;
 print_string "Here are the squares of the numbers you entered: ";
 while (!list)<>Empty do
       let (Cell(number, rest)) = !list in
           print_int (number*number);
           list := !rest;
           print_string " ";
       done;
 print_string "\n\nGood bye!\n\n";;



^ permalink raw reply	[flat|nested] 11+ messages in thread
* Re: overhead of GC in caml runtime?
@ 2000-07-28  9:52 Xavier Leroy
  2000-08-03 19:20 ` Imperative programming in Caml Walid Taha
  0 siblings, 1 reply; 11+ messages in thread
From: Xavier Leroy @ 2000-07-28  9:52 UTC (permalink / raw)
  To: Norman Ramsey, caml-list

> Can anyone tell me approximately what fraction of time is
> spent in garbage collection, or even better, combined allocation and
> collection, in typical caml programs?

It depends how allocation-intensive your program is.  For instance, the
Knuth-Bendix benchmark (which allocates quite a lot of short-lived
data) spends about 20% of its time in GC and allocation in the major
heap, when compiled with ocamlopt on a Pentium.

The percentage is lower for bytecode programs, because the collector
still runs at the same speed while the mutator runs more slowly
because of the interpretation overhead.

Most allocations in the minor heap are expanded in-line, so they can't
be measured.

Hope this helps,

- Xavier Leroy



^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2000-08-09 14:00 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-08-04 18:33 Imperative programming in Caml Don Syme
2000-08-04 19:48 ` Walid Taha
  -- strict thread matches above, loose matches on Subject: below --
2000-07-28  9:52 overhead of GC in caml runtime? Xavier Leroy
2000-08-03 19:20 ` Imperative programming in Caml Walid Taha
2000-08-04 19:43   ` Markus Mottl
2000-08-04 19:57     ` Walid Taha
2000-08-06  1:59       ` John Prevost
2000-08-08 18:01         ` Walid Taha
2000-08-08 18:23           ` John Prevost
2000-08-08 18:30             ` Walid Taha
2000-08-08 21:10               ` Pierre Weis
2000-08-09 13:50                 ` Walid Taha

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox