caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Null pointer
@ 2003-05-22 11:17 Prakash Countcham
  0 siblings, 0 replies; only message in thread
From: Prakash Countcham @ 2003-05-22 11:17 UTC (permalink / raw)
  To: caml-list

   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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-05-22 11:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-05-22 11:17 [Caml-list] Null pointer Prakash Countcham

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).