caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Philippe Veber <philippe.veber@googlemail.com>
To: caml-list@inria.fr
Subject: Closed variants, type constraints and module signature
Date: Fri, 14 May 2010 17:17:37 +0200	[thread overview]
Message-ID: <AANLkTikEddrAoZnT7aPdb86f0KJAnrRRx7pBpa_4l_aM@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 944 bytes --]

I'd like to define a type with a variable that is constrained to accept only
polymorphic variant types included in a given set of tags. That is how I
believed one should do :

        Objective Caml version 3.11.2

# type 'a t = 'a constraint 'a = [< `a | `b ];;
type 'a t = 'a constraint 'a = [< `a | `b ]


But I stumbled upon the following problem, when trying to use this
definition


# module type S = sig
  val v : 'a t
end;;
module type S = sig val v : [< `a | `b ] t end

# module I : S = struct
    let v = `a
  end;;

  Error: Signature mismatch:
       Modules do not match: sig val v : [> `a ] end is not included in S
       Values do not match:
         val v : [> `a ]
       is not included in
         val v : [< `a | `b ] t

Does anyone know why the definition of module I is rejected ? And if this is
the intended behavior, why does the following work ?

# let v : 'a t = `a
  ;;
val v : [< `a | `b > `a ] t = `a


Philippe.

[-- Attachment #2: Type: text/html, Size: 1482 bytes --]

             reply	other threads:[~2010-05-14 15:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-14 15:17 Philippe Veber [this message]
2010-05-14 15:49 ` [Caml-list] " Jacques Garrigue
2010-05-14 21:33   ` Philippe Veber
2010-05-15  0:54     ` Jacques Garrigue
2010-05-17 11:56       ` Philippe Veber
2010-05-17 14:31         ` 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=AANLkTikEddrAoZnT7aPdb86f0KJAnrRRx7pBpa_4l_aM@mail.gmail.com \
    --to=philippe.veber@googlemail.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).