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 RAA03414; Thu, 13 Mar 2003 17:46:03 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id RAA02715 for ; Thu, 13 Mar 2003 17:46:02 +0100 (MET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h2DGk0f05218; Thu, 13 Mar 2003 17:46:00 +0100 (MET) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA03393; Thu, 13 Mar 2003 17:45:59 +0100 (MET) Date: Thu, 13 Mar 2003 17:45:59 +0100 From: Xavier Leroy To: Jakob Lichtenberg Cc: caml-list@inria.fr Subject: Re: [Caml-list] ocaml internal representation Message-ID: <20030313174559.A1781@pauillac.inria.fr> References: <003e01c2e96d$5557a6f0$6401a8c0@redmond.corp.microsoft.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <003e01c2e96d$5557a6f0$6401a8c0@redmond.corp.microsoft.com>; from jl@itu.dk on Thu, Mar 13, 2003 at 06:32:10AM -0800 X-Spam: no; 0.00; caml-list:01 recognized:99 interfacing:01 compiler:01 ocaml:01 int:01 signatures:02 o'caml:02 overhead:03 argument:03 slightly:03 arguments:03 abstract:03 types:03 data:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > In O'Caml the types are compiled away, right? Yes, in a sense, but they are also used to determine memory representation of data to some extent. > Then, is there actually a performance/memory overhead in replacing: > type coord = int * int > with: > type coord = Coord of (int * int) There is no memory overhead with the following two definitions: type coord = Coord of int * int type coord = {x:int; y:int} In both cases, values of type coord will be represented by a two-word memory block (plus one word of header) holding the two integers -- just like a pair of integers int*int. However, there *is* some overhead with your proposed type coord = Coord of (int * int) that is interpreted as "Coord takes one argument that is a pair", causing two memory blocks to be used, one for the pair, one for the application of Coord. In contrast, type coord = Coord of int * int instructs the compiler to treat Coord as taking two arguments that are integers. > Is it recognized as a 'reasonable' way to get the type system to help me not > mixing up stuff (except for signatures of course)? Yes, it's one way to do it. The other is to use abstract types via signature constraints, as you said. > Slightly more general: Did I miss any doc. about this in the O'Caml manual? The chapter "interfacing C with OCaml" contains a *lot* of details on the data representations used by compiled code. Perhaps more details than you'd like to know :-) - Xavier Leroy ------------------- 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