Loading ...
Sorry, an error occurred while loading the content.

2445Re: "ocaml_beginners"::[] A question about "option"

Expand Messages
  • Andy Yang
    Aug 1, 2004
    • 0 Attachment
      I found there are codes as follows:

      let outChannel : out_channel option ref = ref None
      let mergedChannel : out_channel option ref = ref None


      Here, "option" is not used in the 'a option form. Does
      it mean tha outChannel and mergedChannel are two weak
      pointer to references, and these two referenced can be
      reclaimed by the garbage collector at any time?

      Thanks!

      Andy

      --- Martin Jambon <martin_jambon@...> wrote:

      > On Sat, 31 Jul 2004, Andy Yang wrote:
      >
      > > Hi, all
      > >
      > > Do you know where I can find more introduction on
      > the
      > > keyword "option" in Ocaml?
      > >
      > > Basically, option is defined as follows:
      > > type 'a option = None | Some of 'a;
      > >
      > > And I found some codes as follows:
      > >
      > > class backup
      > > object ('a)
      > > val mutable copy : 'a option
      > > method ...
      > > end;;
      > >
      > > If it means a weak pointer, what will happen if
      > the
      > > garbage collector reclaims the memory?
      >
      > Hi,
      >
      > 'a option is a predefined type, which is absolutely
      > not magic and
      > certainly not a keyword.
      > You could have defined it by yourself, but this one
      > is predefined in the
      > core library of OCaml.
      > Normally, this type is used to distinguish between
      > something that has been
      > defined or specified (Some x) and something which is
      > undefined (None).
      >
      > In C, you could use the NULL pointer instead of a
      > valid pointer to express
      > this, but in OCaml you will never have the chance to
      > manipulate invalid
      > data such as an invalid pointer or an uninitialized
      > array.
      >
      > Have a look at the chapter 3 of Richard Jones'
      > tutorial:
      > http://www.merjis.com/developers/ocaml_tutorial/
      >
      >
      > Martin
      >
      >


      __________________________________________________
      Do You Yahoo!?
      Tired of spam? Yahoo! Mail has the best spam protection around
      http://mail.yahoo.com
    • Show all 7 messages in this topic