Infer the type of `x` in `val f: (Int => Int) | Unit = x => x + 1`
See original GitHub issueOr more generally, try harder to infer function literal parameter types from expected type which are unions. The | Unit
usecases matters particularly for scala.js where it’s not uncommon for a parameter type to be written that way (because Unit
corresponds to undefined
in scala.js) but I assume that the explicit nulls language feature could run into the same sort of issues.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6 (4 by maintainers)
Top Results From Across the Web
9.6. Type Inference — OCaml Programming - GitHub Pages
Type Inference #. OCaml and Java are statically typed languages, meaning every binding has a type that is determined at compile time—that is,...
Read more >Type Checking and Type Inference
Type Checking and Type Inference. Type Inference. 1 ... fun f x = (* infer val f : int -> int *) if...
Read more >Inferred type in for comprehension - scala - Stack Overflow
The problem is that the type of the if expression if (bar.cond) `foo.map` += 1 -> "a" else `foo.set` += 2. is State[Foo,...
Read more >Types, Type Inference and Unification
Even integers. {f:int → int | x>3 => f(x) > x *(x+1)}. Distinction between sets of values that are types and sets that...
Read more >Common Error Messages · OCaml Tutorials
"This expression has type X but is here used with type Y" means that if the contents of the expression is isolated (2.5),...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@smarter I can work on this. I think finding the leftmost function type/SAM in the union type would be enough.
I agree with @LPTK. Anything that is not symmetrical will be very volatile.
To avoid backtracking, consider going through the list of elements of the union and throw away the ones that are not SAM types. If you’re left with 1, all good, otherwise abandon.