From: John Max Skaller <skaller@ozemail.com.au>
To: "Jeffrey J. Cook" <jjcook@uiuc.edu>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] polymorphic type constructor deconstructor
Date: Sat, 07 Jun 2003 10:09:44 +1000 [thread overview]
Message-ID: <3EE12D48.7040707@ozemail.com.au> (raw)
In-Reply-To: <20030606223739.GA28169@crhc.uiuc.edu>
Jeffrey J. Cook wrote:
> Hmmm, I didn't make much sense, I'll try again.
It made sense to me, Felix has such a combinator
for internal use called 'case_arg_n', it
returns the argument of a the n'th kind
of constructor of a union without any run time
checking: there's a function 'check_case'
that checks if a value is a particular case,
so a match on a union type is done by:
if (check_case (1, v)) handler1(case_arg_n(1,v));
else if ...
I guess an implementation dependent C function could
be written which checks Ocaml union tag values.
Still, you'd have to manually magic the return type
for each case ..
OcamlP4 might be able to solve the latter problem
so you could write
type t = Ctor1 ctor1_arg_t | Ctor2 ...
deconstruct(Ctor1, v)
which would have type ctor_arg_t as desired.
Deconstruct here would call a Camlp4 macro
which looked up a table generated from the
union declaration for t to find the right
argument type, and to calculate the tag index
to pass to the C function for the run time
check.
[I'm assuming in total ignorance the tags are
sequential from the same origin for each union declared]
--
John Max Skaller, mailto:skaller@ozemail.com.au
snail:10/1 Toxteth Rd, Glebe, NSW 2037, Australia.
voice:61-2-9660-0850
-------------------
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
next prev parent reply other threads:[~2003-06-07 0:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-06-06 21:30 Jeffrey J. Cook
2003-06-06 22:37 ` Jeffrey J. Cook
2003-06-07 0:09 ` John Max Skaller [this message]
2003-06-07 8:22 ` Marcin 'Qrczak' Kowalczyk
2003-06-10 15:28 ` Damien Doligez
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=3EE12D48.7040707@ozemail.com.au \
--to=skaller@ozemail.com.au \
--cc=caml-list@inria.fr \
--cc=jjcook@uiuc.edu \
/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