From: Brian Hurt <bhurt@spnz.org>
To: "Michael D. Adams" <mdmkolbe@gmail.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Efficency of varient types
Date: Sat, 26 Nov 2005 23:45:03 -0600 (CST) [thread overview]
Message-ID: <Pine.LNX.4.63.0511262336031.24132@localhost.localdomain> (raw)
In-Reply-To: <c62c8d860511262106g59cb7bccwcfa24124b97a0a2b@mail.gmail.com>
On Sun, 27 Nov 2005, Michael D. Adams wrote:
> I agree, which is why it was my hope that OCaml might do some of that
> for me. Consider a home brew bool type, "type mybool = Mytrue |
> Myfalse". If the compiler were smart enough, it could represent that
> as an unboxed type.
The compiler is smart enough to do that already- variants without
associated data are represented as ints.
> From there it might be a small step to
> semi-unboxed types such as the one I started this discussion with,
> "type value = Int of int | Bool of bool | String of string".
The problem here is that the variants take two words- one word which says
which variant it is, and the second word which is the unboxed int, unboxed
bool, or pointer to the boxed string.
The problem with unboxing multi-word structures is that this would break
other things. For example, consider List.rev:
let rev lst =
let rec loop accum = function
| h :: t -> loop (h :: accum) t
| [] -> accum
in
loop [] lst
;;
This function has a type of 'a list -> 'a list. Unlike C++ templates,
Ocaml only generates one copy of this function that works on all types.
This is because all the list elements fit into a single word- either their
unboxed types that fit into a single word (int, boolean, char), or the
members of the list are just pointers to the real (boxed) data.
Brian
next prev parent reply other threads:[~2005-11-27 5:39 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-11-25 23:53 Michael D. Adams
2005-11-26 0:31 ` [Caml-list] " Nicolas Cannasse
2005-11-26 1:22 ` Brian Hurt
2005-11-26 9:39 ` Nicolas Cannasse
2005-11-28 0:17 ` Obj or not Obj Christophe Raffalli
2005-11-28 8:41 ` [Caml-list] " Nicolas Cannasse
2005-11-28 9:27 ` Christophe Raffalli
2005-11-28 9:33 ` skaller
2005-11-28 8:43 ` Alain Frisch
2005-11-26 2:54 ` [Caml-list] Efficency of varient types skaller
2005-11-27 5:06 ` Michael D. Adams
2005-11-27 5:45 ` Brian Hurt [this message]
2005-11-27 10:02 ` Nicolas Cannasse
2005-11-27 15:35 ` Michael D. Adams
2005-11-27 18:08 ` Brian Hurt
2005-12-02 15:07 ` Michael D. Adams
2005-11-26 1:18 ` Jon Harrop
2005-11-27 14:57 ` Lukasz Stafiniak
2005-11-27 15:47 ` Lukasz Stafiniak
2005-11-28 8:14 ` Christophe Raffalli
2005-11-28 7:24 ` David Baelde
2005-11-28 7:49 ` Jacques Garrigue
2005-11-28 10:01 ` Jon Harrop
2005-11-28 10:26 ` Luc Maranget
2005-11-28 7:53 ` Ville-Pertti Keinonen
2005-12-01 17:05 ` Stefan Monnier
2005-12-02 15:07 ` [Caml-list] " Michael D. Adams
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=Pine.LNX.4.63.0511262336031.24132@localhost.localdomain \
--to=bhurt@spnz.org \
--cc=caml-list@inria.fr \
--cc=mdmkolbe@gmail.com \
/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