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:19)
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 

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