Open Kmeakin opened 2 years ago
Another consideration is recursive types! If sum types are not anonymous then things become a lot easier, but if they're anonymous it gets tricky. In the latter case, maybe you could use isorecursive types and insert roll
and unroll
during elaboration?
At one stage I was thinking you could add an structural enum
type:
enum { lβ, ..., lβ } : Type
lβ β { lβ, ..., lβ }
ββββββββββββββββββββββββββββββββ
enum lβ : enum { lβ, ..., lβ }
e : enum { lβ, ..., lβ } tβ : t ... tβ : tβ
βββββββββββββββββββββββββββββββββββββββββββββββββββββ
match e { enum lβ => tβ, ..., enum lβ => tβ } : t
Which could be used for the tags of records. This is a bit like Martin LΓΆfβs finite sets (I think?). I was also thinking that there would be some corresponding format for enums as well. In this case weβd need some syntactic sugar or elaborator support to make tagged unions bearable if we went that route. Iβd also imagine that it would require us to implement dependent pattern matching on records (which we donβt yet do). And yeah recursive types, and mutually recursive types could beβ¦ fun?
We already have top level items so maybe it would be easier to go with top level tagged union declarations like Haskell, OCaml, Rust? Save the experimentation for another time and place?
IIRC Mini-TT had some simple form of tagged union that might be interesting to look at.
I think one thing that might help in terms of design is thinking in terms of how this might help us with binary data descriptions. Eg. Looking through the OpenType data description, where would tagged/disjoint unions help us. And also make us think about how we might have corresponding formats that might produce these tagged unions.
Fathom currently has anonymous product types (records), but no (convenient) way of expressing sum types.
Potential solutions
let Option : Type -> Type = fun T => {tag : Bool, value : if tag then T else {}
)let Option : Type -> Type = fun T => sum {None : {}, Some : T}
)Design considerations
Prior Art