From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id WAA12758; Thu, 15 Jul 2004 22:41:35 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id WAA13305 for ; Thu, 15 Jul 2004 22:41:33 +0200 (MET DST) Received: from herd.plethora.net (herd.plethora.net [205.166.146.1]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i6FKfWSH015824 for ; Thu, 15 Jul 2004 22:41:32 +0200 Received: from bhurt.plethora.net (bhurt.plethora.net [205.166.146.49]) by herd.plethora.net (8.11.6/8.10.1) with ESMTP id i6FKfJi27342; Thu, 15 Jul 2004 15:41:21 -0500 (CDT) Date: Thu, 15 Jul 2004 15:48:30 -0500 (CDT) From: Brian Hurt X-X-Sender: bhurt@localhost.localdomain To: John Carr cc: caml-list@inria.fr Subject: Re: [Caml-list] Unboxing options, was RE: assertions or exceptions? In-Reply-To: <200407151956.i6FJuJJJ004332@psi-phi.mit.edu> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Miltered: at concorde with ID 40F6EBFC.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 unboxing:01 boxing:01 boxing:01 enums:01 extlib:01 compiler:01 compiler:01 assertions:01 complexity:02 overhead:03 overhead:03 identical:03 identical:03 wrote:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Thu, 15 Jul 2004, John Carr wrote: > > type 'a option is the same as type 'a option option > > Some Some 1 is identical to Some 1 > > Some None is identical to None > > So use true 0 as opposed to the integer 0 internally represented as 1 > to mean "None". This adds some complexity but may be worth the effort > as options are common. What's the representation of Some(None) then? The Some() goes away, and the containing value is unboxed- it turns out to be the same as just None. There is no way to differentiate Some(Some(Some(Some(None)))) from None. Which I mentioned in my original post. I can see three ways around this. First, just change the behavior, probably adding a switch into the compiler to issue a warning whenever it sees a type of the form 'a option option. This would be under the assumption that very little code actually does options of options (I don't think I've seen any- not to say it doesn't exist, just to say it's not common). Second possibility, have the compiler detect when it's doing an option of an option, and forcibly insert boxing at that point. Third possibility: create a new type, 'a nullable, that has this as the defined behavior. I've seen designs contort themselves in an attempt to avoid the overhead of boxing options- starting with enums in ExtLib. This is an overhead which doesn't have to exist, and we should at least consider eliminating it. -- "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