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

Constructor function naming pattern #662

Merged
merged 1 commit into from
Feb 27, 2024
Merged

Conversation

dfellis
Copy link
Member

@dfellis dfellis commented Feb 27, 2024

In Alan, types are only used at compile time. There's no reflection, so we're free to even decompose the user's variables to just the parts that are necessary, if we wanted to.

And in the language design, they can only be defined at the top-level of a file, you can't define types within a function (since that would require either including a compiler within the compiled output, or some incredibly fancy way to determine at compile time all of the possible types that could be created and then used at run time and pre-build them). You also can't store them in a variable, or etc. They're "just" metadata for the compiler (and eventually intended to be non-required metadata that the compiler can create an substitute for as necessary).

So, the namespace for types vs functions and variables has zero collisions. Which means we can re-use a type's own name for a constructor function. So this PR demonstrates that by renaming the toExitCode functions to just ExitCode, and demonstrating that they work.

When method syntax comes along, it feels like it could be a partial solution to having units, since you could have something like 3.sec() to represent a time delta of seconds, but I do wonder if there's anything "better" that could be done here without making parsing impossible while still looking "better" to human eyes.

@dfellis dfellis self-assigned this Feb 27, 2024
@dfellis dfellis merged commit 047aca5 into main Feb 27, 2024
1 of 2 checks passed
@dfellis dfellis deleted the constructor-function-naming branch February 27, 2024 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant