Constructor function naming pattern #662
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 justExitCode
, 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.