* [Caml-list] Lack of an empty variant type
@ 2020-11-13 11:19 François Pottier
[not found] ` <9F66A427-C0B7-44B6-AE07-330D031FD631@gmail.com>
0 siblings, 1 reply; 2+ messages in thread
From: François Pottier @ 2020-11-13 11:19 UTC (permalink / raw)
To: OCaML Mailing List
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/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-11-17 6:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-13 11:19 [Caml-list] Lack of an empty variant type François Pottier
[not found] ` <9F66A427-C0B7-44B6-AE07-330D031FD631@gmail.com>
2020-11-17 6:38 ` François Pottier
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox