Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Prakash Countcham <countcham_p.nospam@club-internet.fr>
To: caml-list@inria.fr
Subject: [Caml-list] Null pointer
Date: Thu, 22 May 2003 13:17:47 +0200	[thread overview]
Message-ID: <3ECCB1DB.1010504@club-internet.fr> (raw)

   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


                 reply	other threads:[~2003-05-22 11:17 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3ECCB1DB.1010504@club-internet.fr \
    --to=countcham_p.nospam@club-internet.fr \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox