Skip to content
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

Type aliases #495

Open
cie opened this issue Oct 1, 2021 · 2 comments
Open

Type aliases #495

cie opened this issue Oct 1, 2021 · 2 comments
Labels

Comments

@cie
Copy link

cie commented Oct 1, 2021

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)) {
@Sija Sija added feature request language Language feature labels Oct 1, 2021
@gdotdesign
Copy link
Member

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.

@cie
Copy link
Author

cie commented Oct 15, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants