From: Jon Harrop <jon@jdh30.plus.com>
To: caml-list@yquem.inria.fr
Subject: Fwd: Re: [Caml-list] string_of_polymorphic
Date: Mon, 3 Jan 2005 11:20:07 +0000 [thread overview]
Message-ID: <200501031120.07548.jon@jdh30.plus.com> (raw)
> >Why do you want to do this?
>
> Logging purposes, Error handling and so on.
> I have a function that accept some polymorphic constructors as input
> type, and I want to log what is arrived before possibly without writing
> everytime a pattern matching ad-hoc, or raising an exception, I'd like
> to attach the constructor that raised the exception.
If the program is running in the top-level then you may be able to use the
relevant installed pretty printer. I've no idea how though. :-)
> >I think the run-time representation of a polymorphic variants' value is a
> > hash of its name and, therefore, cannot be mapped back onto a string in
> > general. There may be something else you can do specifically for the
> > top-level but I can't think what...
>
> I don't know.
> Polymorphic constructors survive to the marshalling-unmarshalling.
> In the marshalled string, there is a representation of their name.
> That's why I thought there was a method to get their names into a function.
> I think that if Obj is strongly not recommended, analizing a marshalled
> string has to be avoided, so I was looking for other ways.
I believe that the name of a polymorphic variant, as a string, is not in the
marshalled string. Instead, the name is in the type, which is not conveyed by
marshalling. I think the marshalled string will actually contain a fixed-size
hash of the string name.
In theory, two polymorphic variant names which produce the same hash should
be indistinguishable at run-time. Producing them will be tricky though.
A consequence of this is the fixed-size (1-word) of a marshalled polymorphic
variant:
# Marshal.to_string `dkdfbgkadjfbgljbfgljkabhvlkjblvbalvbvlabalbvaslbk [];;
- : string =
"\132\149¦¾\000\000\000\005\000\000\000\000\000\000\000\000\000\000\000\000\0
02í\014âí" # Marshal.to_string `abcd [];;
- : string =
"\132\149¦¾\000\000\000\005\000\000\000\000\000\000\000\000\000\000\000\000\0
02ÀheÂ"
Cheers,
Jon.
reply other threads:[~2005-01-03 11:17 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=200501031120.07548.jon@jdh30.plus.com \
--to=jon@jdh30.plus.com \
--cc=caml-list@yquem.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