caml-list - the Caml user's mailing list
 help / Atom feed
From: François Pottier <>
To: OCaML Mailing List <>
Subject: [Caml-list] Lack of an empty variant type
Date: Fri, 13 Nov 2020 12:19:53 +0100
Message-ID: <> (raw)


I was surprised today to see that this code is rejected:

# let f (x : [< `A]) = ();;
val f : [< `A ] -> unit = <fun>

# let g (x : [< `B]) = ();;
val g : [< `B ] -> unit = <fun>

# fun b x -> if b then f x else g x;;
Error: This expression has type [< `A ]
        but an expression was expected of type [< `B ]
        These two variant types have no intersection

The type-checker rejects this code, even though it is safe,
and its type should be [< ] -> unit, where [< ] is the empty
variant type.

I imagine that the type-checker wants to be my friend and
wants to prevent me from defining a useless function.

However, in the real use case I have in mind, I am abusing
polymorphic variants to encode sets at the type level, and
the lack of an empty set is painful!

Just a random remark,

François Pottier

             reply index

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-13 11:19 François Pottier [this message]
     [not found] ` <>
2020-11-17  6:38   ` François Pottier

Reply instructions:

You may reply publically 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:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

caml-list - the Caml user's mailing list

Archives are clonable: git clone --mirror

AGPL code for this site: git clone public-inbox