Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] assertions or exceptions?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-07-15 (21:28)
From: Brian Hurt <bhurt@s...>
Subject: Re: [Caml-list] Unboxing options, was RE: assertions or exceptions?
On 16 Jul 2004, skaller wrote:

> This is wrong. The representation being suggested is:
> None -> NULL
> Some 'a -> pointer to 'a

No.  Actually, I was suggesting:

None -> NULL
Some 'a -> 'a

which does have this problem.  None isn't the problem- it's a constant in 
both cases.  The problem is the Some case- Some(1) needs to allocate a 
word of memory to hold the 1 in.

By the way, ignore my suggestion that the Ocaml compiler stick in a layer 
of referencing.  You can have a 'a option option without the compiler 
knowing that it's an option option- consider the following bit of code:

let unwrap = function
    | None -> invalid_arg "unwrap"
    | Some x -> x


let pick deflt = function
    | None -> deflt
    | Some x -> x

Having both boxed and unboxed options would make these functions 
impossible to compile.

So the two options are:

1) Change the existing behavior (possibly with a warning)

2) Introduce a new type

Which actually means I'm leaning towards the new type option.

"Usenet is like a herd of performing elephants with diarrhea -- massive,
difficult to redirect, awe-inspiring, entertaining, and a source of
mind-boggling amounts of excrement when you least expect it."
                                - Gene Spafford 

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: