mint
mint copied to clipboard
Type aliases
Hi, Do you plan to have type aliases? The other day I wrote this signature:
fun seq(ps : Array(Function(Array(t), Result(Tuple(String, Array(t)), Tuple(String, Array(t)))))) {
Instead I'd like to write something like
type ParseErr(t) = Tuple(String, Array(t))
type ParseOk(t) = Tuple(String, Array(t))
type Production(t) = Function(Array(t), Result(ParseErr(t), ParseOk(t)))
fun seq(ps : Array(Production(t))) {
or without type parameters and with module scoping
type Grammar.ParseErr = Tuple(String, Array(Token))
type Grammar.ParseOk = Tuple(String, Array(Token))
type Grammar.Production = Function(Array(Token), Result(Grammar.ParseErr, Grammar.ParseOk))
module Grammar {
fun seq(ps : Array(Grammar.Production)) {
In my opinion type aliases adds some complexity when reading code (that's why I didn't implemented it yet) but you're not the first person asking for it, so it will probably happen at some point.
The keyword probably will be alias instead of type.
Thanks! It's not urgent for me.
It can be BTW worked around with a single-valued enum:
enum Production(t) {
Of(Function(Array(t), Result(Tuple(String, Array(t)), Tuple(String, Array(t)))))
}
fun seq(ps: Array(Production(t)))
seq(Production::Of(number))
but that hurts code cleanness on the call site.