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 SAA26990; Fri, 7 May 2004 18:35:28 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 SAA27631 for ; Fri, 7 May 2004 18:35:27 +0200 (MET DST) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from mwinf0102.wanadoo.fr (smtp1.wanadoo.fr [193.252.22.30]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i47GZQEV027386 for ; Fri, 7 May 2004 18:35:26 +0200 Received: from vanicat.homelinux.org (ca-bordeaux-4-39.w80-8.abo.wanadoo.fr [80.8.76.39]) by mwinf0102.wanadoo.fr (SMTP Server) with ESMTP id CE4F51BE69C5 for ; Fri, 7 May 2004 18:35:25 +0200 (CEST) Received: from moi by vanicat.homelinux.org with local (Exim 4.32) id 1BM8Jg-0003vc-2K for caml-list@inria.fr; Fri, 07 May 2004 18:35:16 +0200 To: caml-list@inria.fr Subject: Re: [Caml-list] Differentiating lists from arrays with Obj References: <20040507161855.GA29940@excelhustler.com> From: Remi Vanicat Mail-Copy-To: never Date: Fri, 07 May 2004 18:35:15 +0200 In-Reply-To: <20040507161855.GA29940@excelhustler.com> (John Goerzen's message of "Fri, 7 May 2004 11:18:55 -0500") Message-ID: <87isf8b3gc.dlv@vanicat.homelinux.org> User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 8bit X-Miltered: at nez-perce with ID 409BBACE.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 doubles:01 floats:01 doubles:01 eep:99 interfacing:01 doable:01 arrays:01 arrays:01 ints:01 ocaml:01 ocaml:01 int:01 writes:01 remi:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk John Goerzen writes: > Hello, > > I am looking at using the Obj to access internal representations of some > types. It is generally a bad idea. Why do you need this ? > > I have figured out how to access those types for ints, doubles (floats), > strings, and arrays of doubles (why those are special, I have no > idea!). for optimization reason, and for interface with C. > I can also figure out how to access lists and arrays, for which Obj.tag > returns zero. (Although that value does not occur in obj.ml, it is in > some of the header files.) > > Now, here's the question: how can I accurately differentiate lists from > arrays? You can't. Type information are lost in the midst of the compilation. You cannot recover them. > > Lists appear to be internally represented by structures that look > somewhat like this: > > [1; [2; [3; 0]]] Yes. > > That is, Obj.size will return 2 for the list [1; 2; 3] because it is a > collection of an int and a list. That's fine, but its internal > representation of the list [1] is: > > [1; 0] Exactly > > Which happens to be identical to the representation of the array > [| 1; 0 |]. Eep. And of several other thins (like the couple (1,0), or the couple (true, false), or the couple (1, None), > Now, it's not a big deal to me whether I've got a list or an array, > but I need to be able to know whether that list or array has an > extra 0 at the end. You can't. > > Worse, the internal representation of [] appears to be identical to the > internal representation of the integer 0. And it the same for false, None, and a lot of others.... > I am a little puzzled here, and I do not know the type of the data I'm > dealing with in advance. You should read the "Interfacing ocaml with C" chapter of the manual language, it explain the internal representation of most ocaml value. But there is no miracle : what you try to do is not doable. -- Rémi Vanicat ------------------- 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