Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Naming polymorphic variant types
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-08-21 (04:19)
From: Nick Alexander <nalexander@a...>
Subject: [Caml-list] Naming polymorphic variant types
Hi all,

Here's a file...

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

  val x : outer -> outer
  val y : inner

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

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

  let y = `B

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

That when evaluated, produces...

# #use "C:/Program Files/Objective Caml/";;
module type TEST =
    type outer = [ `A | `B]
    and inner = [ `B]
    val x : outer -> outer
    val y : inner
module Test : TEST
val p : Test.inner = `B
File "C:/Program Files/Objective Caml/", 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 Archives:
Bug reports: FAQ:
Beginner's list: