caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: John Goerzen <jgoerzen@complete.org>
To: caml-list@inria.fr
Subject: [Caml-list] Differentiating lists from arrays with Obj
Date: Fri, 7 May 2004 11:18:55 -0500	[thread overview]
Message-ID: <20040507161855.GA29940@excelhustler.com> (raw)

Hello,

I am looking at using the Obj to access internal representations of some
types.

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!).

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?

Lists appear to be internally represented by structures that look
somewhat like this:

[1; [2; [3; 0]]]

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]

Which happens to be identical to the representation of the array
[| 1; 0 |].  Eep.  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.

Worse, the internal representation of [] appears to be identical to the
internal representation of the integer 0.

I am a little puzzled here, and I do not know the type of the data I'm
dealing with in advance.

Thanks for any enlightenment.

-- John

-------------------
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:[~2004-05-07 16:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-05-07 16:18 John Goerzen [this message]
2004-05-07 16:35 ` Remi Vanicat
2004-05-07 19:00   ` John Goerzen
2004-05-07 20:01     ` Remi Vanicat

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=20040507161855.GA29940@excelhustler.com \
    --to=jgoerzen@complete.org \
    --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;
as well as URLs for NNTP newsgroup(s).