Parametric Aliases Proposal Discussion

Pinging people who I think are interested: @sora @Nick @martinvuyk @Helehex @rd4com

6 Likes

Seems like a pretty clean win here :+1:

What are the advantages (if any) of using:
alias addOne[x: Int] : Int = x + 1
rather than:
fn addOne(x: Int) -> Int: return x + 1

Does a parametric alias that returns an Int offer some kind of advantage over an ordinary function?

I suppose it’s a more contrived example to show what can be done. IIRC, Jeff said in a talk that most things in Mojo are modelled as functions internally anyways.

Aliases are useful for things that don’t have runtime representations, notably literals and types

Sure, but for something that does have a runtime representation, a parametric alias adds no utility, right? It’s basically just a fn that is only invocable at compile-time.

In fact, maybe that’s the point. Maybe you can use a parametric alias to compute a value (such as an Int) that depends on data that isn’t accessible at runtime.

I don’t have a practical example, but maybe one exists.

Building “Config Strings” might be one example, where you have a way to print information about the compiler settings and version used to build the program.