mint icon indicating copy to clipboard operation
mint copied to clipboard

Type aliases

Open cie opened this issue 4 years ago • 2 comments

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)) {

cie avatar Oct 01 '21 06:10 cie

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.

gdotdesign avatar Oct 04 '21 06:10 gdotdesign

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.

cie avatar Oct 15 '21 10:10 cie