RE: reference initialization

From: Dave Berry (dave@kal.com)
Date: Thu May 11 2000 - 15:48:02 MET DST

  • Next message: Charles Neveu: "Re: Netwoking examples.."

    IMO, the "ML strategy" is to use an option type. SML has
            datatype 'a option = NONE | SOME of 'a
    although I prefer
            datatype 'a option = NULL | VALUE of 'a.
    I don't know if Caml provides such a type as standard, although
    it's easy to define your own.

    Then your code checks whether the value has been assigned (dynamically,
    as you require), and can take whatever action is appropriate. If you want
    to throw an exception, you can.

    With this approach, the ML type system tells you which values may be null.
    This has an advantage over the Java approach, where any value may be
    null or uninitialised.

    Dave.

    -----Original Message-----
    From: Hongwei Xi [mailto:hwxi@ececs.uc.edu]
    Sent: Wednesday, May 10, 2000 5:50 AM
    To: caml-list@inria.fr
    Subject: reference initialization

    > Wrong. You have references, which are quite better than pointers
    > (they are typed, and necessarily initialized)

    Suppose I use a reference 'x'. If I know what the initial value
    of 'x' should be, I'll of course prefer to initialize it with that
    value. Now suppose I don't, that is, I intend to assign a value
    to 'v' later (maybe in a loop or in a conditional branch)

    (1) ML strategy: initialize x with any value 'v' of an appropriate
    type (sometimes, such a 'v' is difficult to find or takes time to
    construct (consider 'x' to be a large array)).



    This archive was generated by hypermail 2b29 : Thu May 11 2000 - 19:10:11 MET DST