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

feat(askscript): function type constructor #42

Closed
wants to merge 2 commits into from

Conversation

mhagmajer
Copy link
Collaborator

@mhagmajer mhagmajer commented Jun 4, 2020

fun(returnType, arg1Type, arg2Type, ..., argNType)

Last argument can be rest in this case last argument is true:

fun(string, array(number), true) - same as (s: string, ...numbers: number[]) in TypeScript

Examples

const myToString: fun(string, int) = fun(n:int): string {
  n:toString
}
  • update documentation

@mhagmajer mhagmajer marked this pull request as ready for review June 4, 2020 11:38
@czerwinskilukasz1
Copy link
Collaborator

This PR changes function type used in .ask files to a new syntax.
I think the new syntax is confusing, e.g. fun(int, int, int) doesn't look like the a 2-argument function.
Let's chat about this change.

@czerwinskilukasz1
Copy link
Collaborator

Also, this PR goes beyond the priorities from our Roadmap.
Let's focus on our current priorities before we discuss this syntax change.

@mhagmajer mhagmajer added this to the v1.2 milestone Jun 4, 2020
@mhagmajer
Copy link
Collaborator Author

This PR changes function type used in .ask files to a new syntax.
I think the new syntax is confusing, e.g. fun(int, int, int) doesn't look like the a 2-argument function.
Let's chat about this change.

@czerwinskilukasz1 I'm all for creating some syntax sugar to make it easier to use, see #49

@mhagmajer mhagmajer removed this from the v1.2 milestone Jun 21, 2020
@mhagmajer mhagmajer added AskScript ./src/askscript/** discussion A discussion is taking place, please don't work on it yet enhancement New feature or request labels Jun 30, 2020
@mhagmajer mhagmajer added this to the v1.3 milestone Jun 30, 2020
@czerwinskilukasz1 czerwinskilukasz1 removed this from the v1.3 milestone Jul 1, 2020
@czerwinskilukasz1
Copy link
Collaborator

@mhagmajer , is this PR ready for review? I'd say no, because it links issue #49 , which is about a syntax sugar (int, int) -> int, but there is not such syntax introduced in your change. Instead you use the confusing fun(int, int, int).
I'd convert it to a draft. Thoughts?

@mhagmajer
Copy link
Collaborator Author

mhagmajer commented Jul 6, 2020

@czerwinskilukasz1 this is not the recommended syntax for function type. This is an implementation detail - all types need constructors which are function that result in the given type. Function is a type of value so we need a function constructor for it. We can then have additional syntax sugar for it.

Because types are not checked by runtime yet, I created this PR only for the tests to showcase the basic syntax for creating function types.

Examples of function constructors:

const a: int({ positive: true }) = 5

const b: fun(int, int) = fun (a: int): int { 5 }

// possible syntax sugar:
const c: (int) -> int = fun (a: int): int { 5 }

@czerwinskilukasz1
Copy link
Collaborator

Because types are not checked by runtime yet, I created this PR only for the tests to showcase the basic syntax for creating function types.

Examples of function constructors:

const a: int({ positive: true }) = 5

const b: fun(int, int) = fun (a: int): int { 5 }

// possible syntax sugar:
const c: (int) -> int = fun (a: int): int { 5 }

The ticket description as well as your description in this PR and our discussion in this PR were about a different feature than you mentioned today.

@mhagmajer
Copy link
Collaborator Author

@czerwinskilukasz1 can you explain please? I meant this PR to introduce the generic function type constructor

@czerwinskilukasz1
Copy link
Collaborator

@czerwinskilukasz1 can you explain please? I meant this PR to introduce the generic function type constructor

Of course. The linked issue is about (int, int) -> int syntax:
image

@czerwinskilukasz1
Copy link
Collaborator

Last argument can be rest in this case last argument is true:

fun(string, array(number), true) - same as (s: string, ...numbers: number[]) in TypeScript

I find fun(string, array(number), true) syntax complex and confusing. How about we add ... to AskScript too?

@mhagmajer
Copy link
Collaborator Author

@czerwinskilukasz1 all syntax sugars are useful to make writing code easier :)

@mhagmajer mhagmajer closed this Apr 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AskScript ./src/askscript/** discussion A discussion is taking place, please don't work on it yet enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Syntax sugar for function type and rest arguments
2 participants