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 NAA01486; Thu, 22 May 2003 13:17:58 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id NAA01475 for ; Thu, 22 May 2003 13:17:57 +0200 (MET DST) Received: from imag.imag.fr (imag.imag.fr [129.88.30.1]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h4MBHuT22754 for ; Thu, 22 May 2003 13:17:56 +0200 (MET DST) Received: from club-internet.fr (pc-atinf2.imag.fr [147.171.130.142]) by imag.imag.fr (8.12.9/8.12.9) with ESMTP id h4MBHltL017200 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=OK) for ; Thu, 22 May 2003 13:17:55 +0200 (CEST) Message-ID: <3ECCB1DB.1010504@club-internet.fr> Date: Thu, 22 May 2003 13:17:47 +0200 From: Prakash Countcham User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0) Gecko/20020623 Debian/1.0.0-0.woody.1 MIME-Version: 1.0 To: caml-list@inria.fr Subject: [Caml-list] Null pointer Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-MailScanner: Found to be clean X-MailScanner-Information: Please contact the ISP for more information X-Spam: no; 0.00; 0.010:01 0.000:01 null:01 command:98 int:01 distinguish:01 match:02 native:02 unix:02 nospam:97 pointer:03 string:03 compiling:03 argument:03 types:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi, I wonder if it is possible to implement some optional types (and maybe other data structures) with a null pointer when compiling in native code. It is not possible in general, because we have to distinguish None and Some(None). But in some cases, we know that the argument of Some can't be None. Typically, that is the case of record types that are boxed thus can't be null. So why not adding a keyword that make record types optional for the shake of efficiency. e.g. type record1 = {...} type optional record2 = {...} record2 would be the same as (record1 option), but would be more efficient. The UNIX time command on a PC linux shows a big improvement (more than 40%) in the following example : type recor = {nb:int; ch:string};; let null = {nb=0; ch=""};; let a = Some {nb=1; ch="a"};; let b = {nb=1; ch="a"};; for i = 1 to 100000 do for j = 1 to 10000 do match a with | None -> () | Some c -> ignore(1+c.nb) done done;; (* => 6.970u 0.010s 0:06.98 100.0% 0+0k 0+0io 97pf+0w *) for i = 1 to 100000 do for j = 1 to 10000 do if not (b == null) then ignore(1+ b.nb) done done;; (* => 3.980u 0.000s 0:03.99 99.7% 0+0k 0+0io 97pf+0w *) Thank you for your answer, Prakash Countcham ___________________ ------------------- 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