Re: reference initialization

From: Hongwei Xi (hwxi@ececs.uc.edu)
Date: Thu May 11 2000 - 20:59:16 MET DST

  • Next message: Judicael Courant: "Typechecking of recursive variants"

    Okay, I withdraw my argument that the Java strategy is better then
    the ML strategy However, I'd like to use the following example
    to make my point clear.

    I want to combine two arrays into one. Here is the code in OCaml.

    let combine_arrays a b =
      let alen = Array.length a in
      let blen = Array.length b in
      let c = Array.make (alen + blen) ?
      in begin
        for i = 0 to alen - 1 do
          c.(i) <- a.(i)
        done;
        for i = 0 to blen -1 do
          c.(alen + i) <- b.(i)
        done
      end

    Of course, you need to provide ? to make the above code work.
    Here is my argument:

    (1) If you try to provide ?, the code becomes repulsive.
    (2) If you really want to make sure that 'c' is well-initialized,
    you should probably check this after those two loops. The question
    is how to incorporate the checking result into the type system.
    (3) If you initialize 'c' with a (wrong) value, it seems to me
    that nothing is achieved.
    (4) Also, the problem cannot be solved using option type.

    This is a precise senario that I had in mind, where the kind of
    mandatory array initialization in ML-like langugages is simply
    inappropriate, isn't it?

    Cheers,

    --Hongwei

    \~~~~/ \\ // \\ // @ Mail: hwxi@ececs.uc.edu
    C-o^o, ))__|| \\__//_ // \\ Url: http://www.ececs.uc.edu/~hwxi
    ( ^ ) ))__|| \--/-\\ \\
    / \V\ )) || // \\ \\ Tel: +1 513 556 4762 (office)
    ------ // || o // \\ \\//Fax: +1 513 556 7326 (department)
     



    This archive was generated by hypermail 2b29 : Fri May 12 2000 - 19:17:26 MET DST