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

Extend @typeParam to express lower bound on type parameter #457

Open
jclark opened this issue Mar 11, 2020 · 1 comment
Open

Extend @typeParam to express lower bound on type parameter #457

jclark opened this issue Mar 11, 2020 · 1 comment
Assignees
Labels
enhancement Enhancement to language design lang Relates to the Ballerina language specification
Milestone

Comments

@jclark
Copy link
Collaborator

jclark commented Mar 11, 2020

Our existing @typeParam annotation isn't quite powerful enough to capture the type of stream:toArray. It might seem like you could write:

function toArray(stream<Type,ErrorType?> stm) returns Type[]|ErrorType;

But this isn't quite right, because stream<T,error> is a subtype of stream<T,error?>, so this would allow you to pass an unbounded stream. It would also not be right to say:

function toArray(stream<Type,()> stm) returns Type[];

because that wouldn't allow a bounded stream that might return an error.

When the lang library does:

@typeParam
type XType X;
public function foo(XType t) returns XType = external;

X is the upper bound on the type parameter XType i.e. the type parameter can only be instantiated with a type T that is <= XType (i.e. with a subtype of XType). But for toArray what we need is a lower bound on the type, where the lower bound in this case is nil i.e. that it can only be instantiated with a type T such that () <= T. This is a lower bound that is in addition to the upper bound of error?.

So we will need to devise a way to represent that with an annotation in lang lib.

Originally posted by @jclark in #453 (comment)

@jclark
Copy link
Collaborator Author

jclark commented Mar 11, 2020

We have this problem with stream:reduce already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement to language design lang Relates to the Ballerina language specification
Projects
None yet
Development

No branches or pull requests

1 participant