English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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: 2005-05-06 (03:22)
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

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.


Yahoo! Mail
Stay connected, organized, and protected. Take the tour: