-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sum types? #411
Comments
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 |
At one stage I was thinking you could add an structural
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
The text was updated successfully, but these errors were encountered: