Comments (3)
There might be some cases where this workaround isn't sufficient but I can't find it at the moment.
I honestly don't see it as a workaround, since it amounts to the same number of annotations. I understand that one gets the feeling that ideally no variables should need to be annotated, but if anything, I find that not needing a new (pseudo-?)operator is a cleaner approach, language-wise.
Explicit variable annotations and bidirectional inference do a lot of heavy lifting to resolve the types of things like literal tables (e.g. local t: MyComplexRecord = { ... { ... { ... deeply_nested_thing = ... } ... } ... }
), and this was the primary reason why we added bidirectional inference. Being able to use the same machinery to avoid the need for the "turbofish annotation" felt like a good way to go. The present rule is that variables for function calls are resolved either by the expected types of its return values in the given call-site context, or the types of its given arguments.
from tl.
Teal does bidirectional type inference to try to avoid the need for this.
In your example above, doing local foo: integer = get_foo()
should make the expected type flow into the function call.
Do you have a more complex example where that doesn't work and the explicit generic function argument would still be necessary? I've been trying to see how far we can go without adding more syntax for function calls.
from tl.
So I went back to the case that prompted this request, and found that I was able to avoid the need for an explicit generic by adding more locals with explicit types. There might be some cases where this workaround isn't sufficient but I can't find it at the moment.
from tl.
Related Issues (20)
- extended stdlib by environment HOT 1
- It appears that Issue #646 is not fixed by commit 2fc72bf
- “Lua type masks” codes do not match “Lua types” codes – inconsequential? HOT 3
- Expose `Node` HOT 2
- Nillable record fields HOT 1
- [next branch] Attempt to index nil value `t` HOT 5
- Incorrect "unused argument" warning when using variable arguments HOT 3
- Can a variable be assigned to it's type? HOT 2
- Lua's grammar vs Teal's cast HOT 2
- edge case of checking of the number of return value HOT 2
- Type guard doesn't work properly with unions HOT 2
- Allow indexing (disable type checking) on `any` HOT 5
- How to debug teal code? HOT 1
- Using reserved keyword in record field HOT 4
- [next branch] Total annotation asks for functions too HOT 5
- [next branch] `where` conflicts with `<total>` HOT 3
- No errors reported when assigning value directly to a record table
- Function does not enforce argument record type if variable type is inferred
- Type alias for nested generic crashes compiler HOT 1
- [next] `self` cannot be constrained by an interface
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tl.