From: "Marcin 'Qrczak' Kowalczyk" <qrczak@knm.org.pl>
To: caml-list@inria.fr
Subject: Re: [Caml-list] polymorphic type constructor deconstructor
Date: Sat, 7 Jun 2003 10:22:19 +0200 [thread overview]
Message-ID: <200306071022.19345.qrczak@knm.org.pl> (raw)
In-Reply-To: <20030606223739.GA28169@crhc.uiuc.edu>
Dnia sob 7. czerwca 2003 00:37, Jeffrey J. Cook napisał:
> I would like to simplify this into a function taking a type constructor
> of type 'reply' and a type constructed value of type 'reply' and return
> the contents of the type constructed value, such as (int * int) from
> Foo of int * int. This function would internally have a match statement
> and throw an exception if its not of the right type constructor.
I see no other way than writing these functions manually. Just write them once
and use them instead of passing constructors.
BTW, the contents of 'REPLY_do_that of successlevel * int' is two things
separately, not a pair. You can't match against 'Reply_do_that p'. Similarly
for construction.
> The only solution, using this approach, that I can think of, is by passing
> a dummy constructed value, and pattern matching it against the real
> constructed value, throwing an exception if it isn't of the right
> constructor, otherwise decontructing the value and returning the data
> within.
There is no need for dummy values. Just write a matching function for each
constructor manually. It's not that painful and there is no good other way
anyway.
> So, is there any way to polymorphically deconstruct a type constructed
> value, which is type safe by providing either a dummy constructed value or
> a dummy constructor?
What type would such a deconstructor have?
--
__("< Marcin Kowalczyk
\__/ qrczak@knm.org.pl
^^ http://qrnik.knm.org.pl/~qrczak/
-------------------
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 8:22 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
2003-06-07 8:22 ` Marcin 'Qrczak' Kowalczyk [this message]
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=200306071022.19345.qrczak@knm.org.pl \
--to=qrczak@knm.org.pl \
--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).