Hello, we have polymorphic variants and we also have GADTs. Is there such a thing as a polymorphic generalized variant? Would such a thing even make sense?
p1. I have a hunch that type inference would be hairy and probably depend on explicit type annotations. Maybe somebody with more type theory under their belt could answer.
p2. I donβt see much need for them given that extensible variants can be GADT.
Thank you for your answer. Can you demonstrate how extensible variants can be GADT?
I just now realized this is in the Learning category, and I should have offered to show that without being prompted. Sorry. Hereβs a transcript of a session I just did in utop that hopefully explains how you can do it:
β( 23:48:15 )β< command 0 >β
utop # type _ t = ..;;
type _ t = ..
β( 23:48:15 )β< command 1 >β
utop # type _ t += String: string -> string t;;
type _ t += String : string -> string t
β( 23:48:30 )β< command 2 >β
utop # type _ t += Int: int -> int t;;
type _ t += Int : int -> int t
β( 23:48:47 )β< command 3 >β
utop # String "example";;
- : string t = String "example"
β( 23:48:56 )β< command 4 >β
utop # Int 23;;
- : int t = Int 23
Here, type 'a t
is an extensible GADT, currently with two constructors, String
and Int
. Does that help clarify? Oh, and welcome to OCaml Discuss, @MarcCoquand!
3 Likes
Neat, that clarifies it. Thank you!