Alias Syntax #2030
amitu
started this conversation in
Ideas & RFCs
Alias Syntax
#2030
Replies: 1 comment 1 reply
-
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
We currently do not have any syntax to alias things. We can have:
One can argue we can also do:
So why do we need the alias syntax at all? In fact the later is already supported and is going to be supported in the future as well. Just that
<type-of-$arbitrary-symbol>
is not yet defined. Eg how do write the type of a function, or a component etc?And these are good problems to solve, and we are def going to solve. Our module way of doing thing is to treat the function/component name itself as a type, basically you saying whatever is the type of this function is the type. Which can allow:
This "works" if
bar
is a function or component, but not ifbar
is a record, as this is the syntax we use to create an instance of the record.Even for component I keep thinking
-- <component-name> <id>:
syntax to insert the instance of component and create a variable of typeftd.ui
that stores that instance, so it can be referred from other documents etc.In light of this, I feel alias can be good addition to the language. Alias is a bit more explicit I feel, it feels a little more lightweight, you are just aliasing something.
Alias and Export Rename
@xypnox asked for export rename feature, which is a good addition. It too can be handled via alias:
Import Desugaring
The reason I was thinking of this syntax is because we can then desugare the import statement using aliases:
Can be desugared into:
full module name with # separator should also be allowed as discussed elsewhere.
We can de-sugar
export/exposing: *
by creating appropriate private or public aliases for each symbol defined in imported module.De-sugars into:
And so on.
exposed
stuff are not exported, so we do not mark those aliases public.De-sugars into:
Alias Conflict
If we are doing
export: *
etc, and have a symbol with same name defined, is it an error, or our symbol which is technically defined later on, shadows the exported symbol, or do we follow the order of definition/import to pick the last value?I prefer it is an error for you to explicitly expose x and define x, similarly export desugar alias conflicting with defined symbols should be an error, but if we are implicitly exposing x via de-sugaring, then shadowing is the better behaviour. This is what Rust does. By default
Result
isstd::result::Result
, so it has been "exposed", but we can still create our ownResult
type and overwrite it.Beta Was this translation helpful? Give feedback.
All reactions