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

Add proper declarations #33

Closed
effectfully opened this issue Sep 20, 2019 · 6 comments
Closed

Add proper declarations #33

effectfully opened this issue Sep 20, 2019 · 6 comments

Comments

@effectfully
Copy link
Owner

Now that we plan to add arrays and functions, distinguishing between variables of different types by means of weird syntactic tricks is no longer an option, we need proper type signatures.

@jakzale
Copy link
Collaborator

jakzale commented Mar 31, 2020

@effectfully, #13 mention external variables.

Are declarations four bound variables, or do we declare free/external variables as well?

@effectfully
Copy link
Owner Author

effectfully commented Mar 31, 2020

Declarations are only for free/external variables. For a bound/internal variable we can annotate its rhs with a type at the definition site (or not do that if the type is unambiguous, which is currently probably always the case).

So we need declarations precisely because those external variables are not bound anywhere and we have to specify their types somehow. And it also helps readability to declare all external variables upfront.

@jakzale
Copy link
Collaborator

jakzale commented Mar 31, 2020

Right, because we do not have functions, and we cannot properly specify an interface or an entry point to the program. I think that once we add functions then we get rid of declarations by specifying which function is an entry point of the program, and then specifying that functions arguments.

Circling back to #51, do we want to

  • go the direction of imperative languages and have declarations as a statement, or
  • go the direction of functional languages and have declarations as lexical scoping bindings (without RHS)?

@effectfully
Copy link
Owner Author

Right, because we do not have functions, and we cannot properly specify an interface or an entry point to the program. I think that once we add functions then we get rid of declarations by specifying which function is an entry point of the program, and then specifying that functions arguments.

That's an interesting perspective, I haven't thought of it. We can have the same convention as in Haskell: main is the entry point.

That means that we'll have to distinguish between functions and procedures, though. Just like we distinguish between expressions and statements right now (which is something that we have to do, because assertions can only be compiled when they're at the top level, see this comment, so "statements" arise naturally).

I.e. you can call a function (that can't contain any statements) only from an expression and a procedure (which is a bunch of statements) call is a treated as a statement. In that sense a for loop is a procedure.

I now think we should start with #51 first, otherwise it's too hard to change the language so that the changes make sense right now and after we fix #51.

What do you think?

@jakzale
Copy link
Collaborator

jakzale commented Mar 31, 2020

Ok, I will focus on #51 first.

@jakzale
Copy link
Collaborator

jakzale commented Aug 4, 2020

Fixed by #79

@jakzale jakzale closed this as completed Aug 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants