Type inference issue involve type alias and higher-kinded type
See original GitHub issueAs discussed in https://gitter.im/lampepfl/dotty?at=6033a71be634904e60b71e22
Compiler version
3.0.0-RC1
Minimized code
trait Functor[F[_]] {
def map[A, B](fa: F[A]): F[B]
}
object data {
opaque type OptionT[F[_], A] = F[Option[A]]
extension [F[_], A](value: OptionT[F, A]) {
def fold[B](default: => B)(f: A => B)(using F: Functor[F]): F[B] =
F.map(value)(_.fold(default)(f))
def cata[B](default: => B, f: A => B)(using x: Functor[F]): F[B] =
fold(default)(f)(using x)
}
}
Output
Compiler error
[error] -- [E050] Type Error: /Users/tim/dev/cheetahs/core/src/main/scala/io/github/timwspence/cheetahs/data.scala:30:11
[error] 30 | F.map(value)(_.fold(default)(f))
[error] | ^^^^^^^^^^^^
[error] | method map in trait Functor does not take more parameters
[error] -- [E007] Type Mismatch Error: /Users/tim/dev/cheetahs/core/src/main/scala/io/github/timwspence/cheetahs/data.scala:33:29
[error] 33 | fold(default)(f)(using x)
[error] | ^
[error] |Found: (x : io.github.timwspence.cheetahs.Functor[F])
[error] |Required: io.github.timwspence.cheetahs.Functor[F²]
[error] |
[error] |where: F is a type in method cata with bounds <: [_$3] =>> Any
[error] | F² is a type variable with constraint >: [X0] =>> io.github.timwspence.cheetahs.data.OptionT[F, X0] | F[X0] and <: [_$3] =>> Any
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (7 by maintainers)
Top Results From Across the Web
Yet another Higher Kinded Types proposal in Typescript #44875
I am proposing that Higher order types be added in the truest since, that is, there is a strict hierarchy of type orders,...
Read more >What are the limitations on inference of higher-kinded types in ...
Scala in general doesn't have trouble with higher-kinded types. This is one of several key features that distinguishes its type system from, ...
Read more >Higher-Kinded Types in Dotty - Scala 3
In the new scheme, only classes (and traits) can have parameters and these are treated as equivalent to type members. Type aliases and...
Read more >1598-generic_associated_types - The Rust RFC Book
"Higher-kinded types" is a vague term, conflating multiple language ... which looks a lot like the syntax for creating aliases for type constructors....
Read more >Lightweight higher-kinded polymorphism
Higher-kinded polymorphism —i.e. abstraction over type con- ... Defining Unless in OCaml involves binding three modules. ... 1.1 The alias problem.
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
Before we dealias, we should be compared the applied types as written, it looks like this is done but failing, looking around this seems to fix it:
now running the tests to see if this break anything, but this looks promising 😃
Minimized without the cats dependency:
This compiles with Scala 2.