From: "Nick Alexander" <nalexander@amavi.com>
To: <garrigue@kurims.kyoto-u.ac.jp>
Cc: <caml-list@inria.fr>
Subject: Re: [Caml-list] Naming polymorphic variant types -- additional questions
Date: Wed, 21 Aug 2002 18:26:36 -0700 (PDT) [thread overview]
Message-ID: <1066.207.194.7.55.1029979596.squirrel@mail.gx.ca> (raw)
In-Reply-To: <20020821142724W.garrigue@kurims.kyoto-u.ac.jp>
> From: "Nick Alexander" <nalexander@amavi.com>
>
>> module type TEST =
>> sig
>> type outer = [ `A | `B]
>> and inner = [ `B]
>> val x : outer -> outer
>> val y : inner
>> end
>> module Test : TEST
>> # let p = Test.y;;
>> val p : Test.inner = `B
>> # let q = Test.x p;;
>> ^
>> This expression has type Test.inner = [ `B] but is here used with type
>> Test.outer = [ `A | `B]
>> The first variant type does not allow tag(s) `A
>>
>> I'm confused. Can I get an explanation for why the parameter to a
>> function with a sum variant type needs all summands to be possible
>> arguments?
>
> Inner is a subtype of outer, but they cannot be unified (unification
> requires equality, not subtyping).
>
> You can get subtyping by writing explicit coercions:
>
> # let q = Test.x (p :> Test.outer);;
> val q : Test.outer = `A
>
> You can also give polymorphic types to your values in the interface:
> val x : [< outer] -> outer
> and
> val y : [> inner]
> are both valid, and one of them is enough to allow (Test.x p) without
> coercion. I.e., [< outer] can be unified with inner, and [> inner] can
> be unified with outer.
When I was trying this, I accidently tried:
type outer = [< 'A | 'B]
and was duly rewarded with
Unbound type parameter [..]
I understand that this is not what Jacques recommended! I'm wondering if
someone can tell me what this means, and when this construction could
possibly be necessary.
I am also a neophyte polymorphic variants user. It seems very intuitive
to me that [`A] is a subtype of [`A | `B]. Jacques informs me that
unification rejects the subtyping in favour of equality. So, what is the
situation where [`A] is _not_ a subtype of [`A | `B]? Ie, what common
construct, design pattern, or idiom reflects this?
Thanks for the great support,
Nick
-------------------
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:[~2002-08-22 1:24 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-08-21 4:22 [Caml-list] Naming polymorphic variant types Nick Alexander
2002-08-21 5:27 ` Jacques Garrigue
2002-08-21 16:02 ` Nick Alexander
2002-08-21 23:50 ` Jacques Garrigue
2002-08-22 1:26 ` Nick Alexander [this message]
2002-08-22 14:26 ` [Caml-list] Naming polymorphic variant types -- additional questions Jacques Garrigue
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=1066.207.194.7.55.1029979596.squirrel@mail.gx.ca \
--to=nalexander@amavi.com \
--cc=caml-list@inria.fr \
--cc=garrigue@kurims.kyoto-u.ac.jp \
/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