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 Thu, 15 Jul 2004, John Carr wrote:

> There is also no way to distinguish 0 from None in the current
> system.  OCaml relies on type information to determine the meaning
> of a value.

Yes, but in Some(0), the 0 is boxed (because of the Some)- so Some(0) is 
different from None.  I trust the type checker to make sure I can't have 0 
and None in the same variable, just like I trust the type checker to make 
sure I can't have 0 and false in the same variable.

> 
> Is there valid code (no Obj.magic) that cares that (Some None) and
> (None) are both represented by the same bit pattern?

let foo = function
    | None -> 0
    | Some(None) -> 1
    | Some(Some(_)) -> 2
;;

Now, wether you would actually see code like that in the "real world" is a 
different argument.

-- 
"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