gluon-lang / gluon

A static, type inferred and embeddable language written in Rust.
https://gluon-lang.org
MIT License
3.21k stars 145 forks source link

Generalized algebraic data types #219

Open brendanzab opened 7 years ago

brendanzab commented 7 years ago

Would be lovely to have GADTs!

Eg.

type Expr : Type -> Type =
    | Bool  : Bool     -> Expr Bool
    | Int   : Int      -> Expr Int
    | Equal : Expr Int -> Expr Int  -> Expr Bool

type StateEff : Type -> Type -> Type =
    | Get : StateEff s s
    | Put : s -> StateEff s ()
brendanzab commented 7 years ago

Not sure how row polymorphism fits in with this though - I haven't really been able to find anything in the literature about it row polymorphic GADTs.

I am wondering if our unions should be closed by default, but that is a different discussion...

Marwes commented 7 years ago

Closed by default seems like what one wants most of the time. No idea how row polymorphism works with GADTs either. GADTs do make inference undecidable however so possibly row-polymorphism would make it even more undecidable (not that the current type system is decidable either, but there is a risk of introducing to much undecidable constructs).

Nadrieril commented 6 years ago

GADTs can have decidable inference with only a few annotations (see here for example), at least in system F. In Fω however, i.e. with arbitrary type lambdas, I'm not sure this would work as well...