From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id C90A0BB9C for ; Sun, 27 Nov 2005 06:39:35 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id jAR5dZLQ027215 for ; Sun, 27 Nov 2005 06:39:35 +0100 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 GAA12933 for ; Sun, 27 Nov 2005 06:39:34 +0100 (MET) Received: from conn.mc.mpls.visi.com (conn.mc.mpls.visi.com [208.42.156.2]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id jAR5dX81027207 for ; Sun, 27 Nov 2005 06:39:34 +0100 Received: from [192.168.42.2] (bhurt.dsl.visi.com [208.42.141.66]) by conn.mc.mpls.visi.com (Postfix) with ESMTP id 0F3938252; Sat, 26 Nov 2005 23:39:33 -0600 (CST) Date: Sat, 26 Nov 2005 23:45:03 -0600 (CST) From: Brian Hurt X-X-Sender: bhurt@localhost.localdomain To: "Michael D. Adams" Cc: caml-list@inria.fr Subject: Re: [Caml-list] Efficency of varient types In-Reply-To: Message-ID: References: <4387ACC9.2040107@motion-twin.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Miltered: at nez-perce with ID 43894697.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 43894695.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 ocaml:01 bool:01 compiler:01 unboxed:01 compiler:01 variants:01 bool:01 variants:01 unboxed:01 pointer:01 unboxing:01 multi-word:01 rec:01 accum:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 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