Version française
Home     About     Download     Resources     Contact us    
Browse thread
unboxing options
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Charles Martin <chaspost@y...>
Subject: unboxing options
This is reviving a thread from last summer, but I
recently became interested in the problem:

Damien Doligez <damien.doli...@inria.fr> wrote in
message news:<fa.eok2n4f.141k5pt@ifi.uio.no>...
> Finally, Jacques was not quite right in asserting
that most options
> are short-lived.  This is only true if you don't use
"option" in your
> main long-lived data structure.  Most seasoned OCaml
programmers know
> it, and sometimes it leads to rather contorted data
structures.

How easy would it be to add an 'optional' keyword for
record types? For example:

    type 'a foo = { one : 'a option; mutable two : 'a
option }

would become:

    type 'a foo = { optional one : 'a; optional
mutable two : 'a }

Where the latter would unbox the options in the
representation. The
usage would be the same:

    let foo = { one = Some 0; two = None }
    match foo.one with None -> ... | Some x -> ...
    foo.two <- None
    foo.two <- Some x

This 'solves' the 'option option' problem by
supporting exactly one level of unboxing for records.
My guess is that this would take care of most of the
long-term data structure needs.

Charles



		
Yahoo! Mail
Stay connected, organized, and protected. Take the tour:
http://tour.mail.yahoo.com/mailtour.html