Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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
;;

Or:

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 
Brian

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners