caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Recursive fixed polymorphic variants
@ 2013-05-27 16:30 Jacques-Pascal Deplaix
  2013-05-28  6:36 ` Erkki Seppala
  2013-05-28  8:13 ` Leo White
  0 siblings, 2 replies; 5+ messages in thread
From: Jacques-Pascal Deplaix @ 2013-05-27 16:30 UTC (permalink / raw)
  To: OCaml mailing list

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

Hi,

I have a problem with this test-case which doesn't compile:

module M : sig
  type a = [`A]
  type 'a b = [`B of 'a]

  val a : unit -> a
  val b : 'a -> 'a b
end = struct
  type a = [`A]
  type 'a b = [`B of 'a ]

  let a () = `A
  let b x = `B x
end;;

let rec f = function `B x -> f x | `A -> ();;

f (M.b (M.a ()));;

and produce the following error:

Error: This expression has type M.a M.b = [ `B of M.a ]
       but an expression was expected of type [< `B of 'a ] as 'a
       Type M.a = [ `A ] is not compatible with type M.a M.b = [ `B of
M.a ]
       These two variant types have no intersection

The thing is, if we define M.a and M.b with « unit -> [> a ] » and « 'a
-> [> 'a b ] », it does compile but I don't know why the previous code
doesn't.

Does somebody have any hints ?

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

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

end of thread, other threads:[~2013-05-28 21:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-27 16:30 [Caml-list] Recursive fixed polymorphic variants Jacques-Pascal Deplaix
2013-05-28  6:36 ` Erkki Seppala
2013-05-28  8:20   ` Leo White
2013-05-28  8:13 ` Leo White
2013-05-28 21:01   ` Jacques-Pascal Deplaix

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