Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Using generics instead of type inference on structs and functions #2

Open
ghost opened this issue Feb 11, 2019 · 3 comments
Open

Using generics instead of type inference on structs and functions #2

ghost opened this issue Feb 11, 2019 · 3 comments

Comments

@ghost
Copy link

ghost commented Feb 11, 2019

Instead of full blown type inference (which will be VERY hard to do because of python's loose, dynamic typing), why not make the resulting code generate generics, and then halt the transpiling if it sees type changing?

I can help implement. If you need, let me know.

@ghost ghost closed this as completed Feb 11, 2019
@ghost ghost reopened this Feb 11, 2019
@konchunas
Copy link
Owner

I sure wouldn't mind a help. You see, currently transpiler is already generates generics for method arguments. It's half way there for structs too. But the main problem here is type bounds. So if you have a generic type argument and do, for example, math operations on it, this type should be bound by where clause.
You can check it by simple python example:

def foo(bar):
  bar = bar - 5;

This will make bar to be generic type T0, but compiler will say that op::Sub is not implemented for T0
That's the main problem

@ghost
Copy link
Author

ghost commented Feb 11, 2019

@konchunas
What I would then suggest is doing some kind of parsing on whatever the variables are assigned to initially. If the variable is reassigned, parse it again and if it fails to parse or produces a different output, you know the types changed. If you do any kind of integer operations or see that the type is an integer, automatically implement the required trait to the function.

@konchunas
Copy link
Owner

When dealing with this transpiler you don't deal with script evaluation, we more deal with Syntax Tree. But you can take a look at this call to get a grasp on what I think is the idiomatic way to search in Syntax Tree.

You could investigate if it is difficult to search for variable assignments inside some scope (e.g. function body) using similar method.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant