Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Jacques-Pascal Deplaix <jp.deplaix@gmail.com>
To: OCaml mailing list <caml-list@inria.fr>
Subject: [Caml-list] Recursive fixed polymorphic variants
Date: Mon, 27 May 2013 18:30:27 +0200	[thread overview]
Message-ID: <51A38A23.9000402@gmail.com> (raw)

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

             reply	other threads:[~2013-05-27 16:30 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-27 16:30 Jacques-Pascal Deplaix [this message]
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

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=51A38A23.9000402@gmail.com \
    --to=jp.deplaix@gmail.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