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

Implement Powerful Generics #17

Open
joshradin opened this issue Apr 3, 2020 · 1 comment
Open

Implement Powerful Generics #17

joshradin opened this issue Apr 3, 2020 · 1 comment
Labels
enhancement New feature or request Language Related to the language
Milestone

Comments

@joshradin
Copy link
Owner

Minimum Implementation

Generic objects can be defined using the for <T, ...> clause on any top level declaration.
This creates a generic type declaration. Generic types aren't actually translated to code directly. For compound types, any time a initialization process is called for a generic type, an implementation is generated that metamorphosizes the original declaration for the new types. For functions, this occurs anytime the function is called.

An instance can be declared for a generic type with invariance, contravariance, and covariance using the follow syntax:
Type<T> for invariance
Type<? : T> for covariance
Type<T : ?> for contravariance

Generic declarations can have bounds, like so:
for<T : Object>.
This is also the default bound.

Extended Implementation

Variable Length parameters

Enable multiple generic implementations per a single type based on number of arguments. For example for <T> class type and for <T, R> class type will be two separate implementations of the same type.
In addition, generics can have variadic argument in the last position using the following form:
for <T1, T2, ..., Tn, (HD:TL) (: bound)?>. The HD declaration is the first type parameter in the list, the TL part represents everything else. Both arguments can be empty. If the HD or TL is placed after a comma, but it is empty, the comma is ignored in terms of parameter count.
The following is can example of a use case for this:

for <R, (HD:TL)> class fn {
    private fn<fn<R : ?, ? : TL>, HD> next;

    public R enact(HD arg1, args...) {
        fn<R : ?, ? : TL> func = next->enact(args1);
        return func(args);
    }
}

for <R> class fn {
    public R enact();
}
@joshradin joshradin added the enhancement New feature or request label Apr 3, 2020
@joshradin joshradin added this to the v0.4-alpha milestone Apr 3, 2020
@joshradin joshradin added the Language Related to the language label Apr 3, 2020
@joshradin
Copy link
Owner Author

Current implementation parses part of the Generic representation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Language Related to the language
Projects
None yet
Development

No branches or pull requests

1 participant