I read existing questions about how type definitions with parameterized bounds are illegal inside blocks (or something to that effect), but it doesn't help me in my problem:
type Cons[X]
class Higher[C[X] <: Cons[X]]
type AnyHigher = Higher[C] forSome { type C[X] <: Cons[X] }
Seq[AnyHigher]().map { h => h }
compiler:
can't existentially abstract over parameterized type C
Seq[AnyHigher]().map { h => h }
The element type of the input collection is irrelevant, the problem lies only in the return type of the mapping function. Is there any way around this? I tried various refactors: making the mapping function a method, cheating by making the code generic and executing parameterized with AnyHigher, writing my own recursion, but nothing helps.
A workaround is
"can't existentially abstract over parameterized type..."
Another workaround is to make
C[X]a type member rather than type parameterand use
Higher.Aux[C]instead ofHigher[C]andHigherinstead ofHigher[C] forSome { type C[X] <: Cons[X] }.http://dotty.epfl.ch/docs/reference/dropped-features/existential-types.html
https://scalacenter.github.io/scala-3-migration-guide/docs/incompatibilities/dropped-features.html#existential-type