-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Missing type upper bound for Tuple.Fold
#13813
Comments
We can do a small workaround here to avoid type Reverse[X <: Tuple] <: Tuple = X match
case _ => Fold[X, EmptyTuple, [A <: Tuple, Y] =>> Y *: A]
-- [E007] Type Mismatch Error----------------------------------------------
2 | case _ => Tuple.Fold[X, EmptyTuple, [A <: Tuple, Y] =>> Y *: A]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|Found: Tuple.Fold[X, EmptyTuple, [A <: Tuple, Y] =>> Y *: A]
|Required: Tuple The problem is, I think it's a bit of a case where we really can't ever infer from So if we want something like type Reverse[X <: Tuple] <: Tuple = X match
case EmptyTuple => EmptyTuple
case h *: t => Tuple.Append[Reverse[t], h] In that case, everything works great. The issue is, that we cannot write something akin to type A <: List[Any] = List[Int] Because the type of alias may depend on other types, which may lead to unsoundness. |
Combining @nicolasstucki's proposed signature type Fold[Tup <: Tuple, Z, F[_, _]] <: (Z | F[_, _]) = ... with @Decel's trick for type Reverse[X <: Tuple] <: Tuple = X match
case _ => Fold[X, EmptyTuple, [A <: Tuple, Y] =>> Y *: A] should make it work. In fact, -type Reverse[X <: Tuple] <: Tuple = X match
+type Reverse[X <: Tuple] <: Tuple = Any match
case _ => Fold[X, EmptyTuple, [A <: Tuple, Y] =>> Y *: A] Alternatively, with the updated signature for -type Reverse[X <: Tuple] <: Tuple = Fold[X, EmptyTuple, [A <: Tuple, Y] =>> Y *: A]
+type Reverse[X <: Tuple] = Fold[X, EmptyTuple, [A <: Tuple, Y] =>> Y *: A] |
I found that type Fold[Tup <: Tuple, R, Z <: R, F[_, _ <: Tuple] <: R] <: R = Tup match
case EmptyTuple => Z
case h *: t => F[h, Fold[t, R, Z, F]]
type Reverse[X <: Tuple] = Fold[X, Tuple, EmptyTuple, [H, T <: Tuple] =>> H *: T] |
Ah, unfortunately that would not be a backward TASTy compatible change. :( |
Neither would adding any bound to the match type though - I would think?! |
It already has a bound, which is Edit: it's similar to making the result type of final term function a strict subtype of what it was before. |
I think even a subtype isn't compatible, if you consider the use of that result type in a method like foldLeft. But is that only source incompatibility? |
That's only source incompatibility, yes. |
Compiler version
3.1.0
Code
The current definition for
Tuple.Fold
isIt should know that the result will be a subtype of
Z
orF
. It looks like we should be able to add this bound but it does not work.Failing example
Expectation
Should be able to add these kinds of bounds
The text was updated successfully, but these errors were encountered: