caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Nick Alexander" <nalexander@amavi.com>
To: <caml-list@inria.fr>
Subject: [Caml-list] Naming polymorphic variant types
Date: Tue, 20 Aug 2002 21:22:21 -0700 (PDT)	[thread overview]
Message-ID: <1413.207.194.7.18.1029903741.squirrel@mail.gx.ca> (raw)

Hi all,

Here's a file...

module type TEST = sig
  type outer = [`A | `B]
  type inner = [`B]

  val x : outer -> outer
  val y : inner
end

module Test : TEST = struct
  type outer = [`A | `B]
  and inner = [`B]

  let x o = match o with
  | `A -> `A
  | `B -> `A

  let y = `B
end

let p = Test.y
let q = Test.x p

That when evaluated, produces...

# #use "C:/Program Files/Objective Caml/test.ml";;
module type TEST =
  sig
    type outer = [ `A | `B]
    and inner = [ `B]
    val x : outer -> outer
    val y : inner
  end
module Test : TEST
val p : Test.inner = `B
File "C:/Program Files/Objective Caml/sql5.ml", line 21, characters 15-16:
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?  I'm sure I'm misunderstanding the subtyping relationship, but
I can't hack it.  This all grew out of a desire to document code by naming
polymorphic variant types, a questionable capability at best.
Any light appreciated,
Nick Alexander


-------------------
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


             reply	other threads:[~2002-08-21  4:19 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-08-21  4:22 Nick Alexander [this message]
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   ` [Caml-list] Naming polymorphic variant types -- additional questions Nick Alexander
2002-08-22 14:26     ` Jacques Garrigue
2002-08-22  0:04 [Caml-list] Naming polymorphic variant types Nick Alexander
2002-08-23 22:38 ` John Max Skaller

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=1413.207.194.7.18.1029903741.squirrel@mail.gx.ca \
    --to=nalexander@amavi.com \
    --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).