From: Dario Teixeira <darioteixeira@yahoo.com>
To: caml-list@yquem.inria.fr
Subject: Union of type variables
Date: Sat, 31 Jan 2009 08:55:22 -0800 (PST) [thread overview]
Message-ID: <725185.7305.qm@web111505.mail.gq1.yahoo.com> (raw)
Hi,
Consider the following toy experiment with phantom types. Note that the shown
implementation of function "union" is far from optimal; though it takes only
two arguments, these are being passed as a list. This is basically just a
kludge that forces the phantom type in the return type to be also a union.
module M:
sig
type 'a t
val a: int -> [> `Foo ] t
val b: int -> [> `Foo ] t
val c: int -> [> `Bar ] t
val d: int -> [> `Bar ] t
val union: 'a t list -> 'a t
end =
struct
type foobar_t =
| A of int
| B of int
| C of int
| D of int
| Union of foobar_t * foobar_t
type 'a t = foobar_t
let a x = A x
let b x = B x
let c x = C x
let d x = D x
let union (x :: y :: []) = Union (x, y)
end
Obviously I would like to get rid of this kludge. The signature and
implementation for "union" should be something like the (syntactically
incorrect) code below. But is it at all possible to declare an union
of type variables? (which presupposes they are polymorphic variants)
val union: 'x t -> 'y t -> [> 'x | 'y ] t
let union x y = Union (x, y)
Thanks in advance!
Best regards,
Dario Teixeira
next reply other threads:[~2009-01-31 16:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-31 16:55 Dario Teixeira [this message]
2009-02-02 17:07 ` [Caml-list] " Dario Teixeira
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=725185.7305.qm@web111505.mail.gq1.yahoo.com \
--to=darioteixeira@yahoo.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