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

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

Expand Messages
  • Matt Gushee
    Aug 1, 2004
    • 0 Attachment
      On Sun, Aug 01, 2004 at 09:58:51AM -0700, Andy Yang wrote:
      >
      > 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?

      No, not at all.

      Having 'out_channel option' rather than ''a option' just means that the
      type is completely specified. If you were to specify 'a option in a type
      or function signature, it would indicate polymorphism. Since this is a
      non-functional value, it can't be polymorphic, but 'a option would allow
      the specific type represented by 'a to be defined later.

      Since it is a ref, it is mutable. So this example is equivalent to
      declaring (but not initializing) a variable in C.

      It seems you really want to make a connection between the option type
      and weak pointers. As far as I know there is none. Are you just trying
      to learn, or do you have a specific usage in mind?

      --
      Matt Gushee When a nation follows the Way,
      Englewood, Colorado, USA Horses bear manure through
      mgushee@... its fields;
      http://www.havenrock.com/ When a nation ignores the Way,
      Horses bear soldiers through
      its streets.

      --Lao Tzu (Peter Merel, trans.)
    • Show all 7 messages in this topic