caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Closed variants, type constraints and module signature
@ 2010-05-14 15:17 Philippe Veber
  2010-05-14 15:49 ` [Caml-list] " Jacques Garrigue
  0 siblings, 1 reply; 6+ messages in thread
From: Philippe Veber @ 2010-05-14 15:17 UTC (permalink / raw)
  To: caml-list

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-05-17 14:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-14 15:17 Closed variants, type constraints and module signature Philippe Veber
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

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