From: "François Pottier" <francois.pottier@inria.fr>
To: OCaML Mailing List <caml-list@inria.fr>
Subject: [Caml-list] Lack of an empty variant type
Date: Fri, 13 Nov 2020 12:19:53 +0100 [thread overview]
Message-ID: <b472db9f-eace-45cf-624f-76564337a59b@inria.fr> (raw)
Hello,
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
francois.pottier@inria.fr
http://cambium.inria.fr/~fpottier/
next reply other threads:[~2020-11-13 11:19 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-13 11:19 François Pottier [this message]
[not found] ` <9F66A427-C0B7-44B6-AE07-330D031FD631@gmail.com>
2020-11-17 6:38 ` François Pottier
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=b472db9f-eace-45cf-624f-76564337a59b@inria.fr \
--to=francois.pottier@inria.fr \
--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