Skip to content

Dealias type when type parameters inference occurs #23242

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Alex1005a
Copy link
Contributor

The code below displays the type parameter [Res] =>> TypeAl[F, String, Res] for the toFunctorOps implicit conversion.

import cats.Functor
import cats.syntax.all.*

type Result[F[_], Err, Res] = F[Either[Err, Res]]

def test[F[_]: Functor](x: Result[F, String, Int]) = {
  x.map(identity) // error here
}

To fix this, you can do dealias if the type before dealias does not have the same arity as the constructor with which unification occurs, but the type after dealias does have the same arity. Then the type parameter F will be inferred.

@Alex1005a Alex1005a marked this pull request as ready for review May 23, 2025 19:05
@Gedochao Gedochao requested review from som-snytt and odersky June 5, 2025 05:11
@odersky odersky requested a review from smarter June 5, 2025 11:26
@odersky
Copy link
Contributor

odersky commented Jun 5, 2025

I think @smarter would be the best person to review this. Guillaume, can you take a look? You have thought most about dealiasing and type inference.

@odersky odersky assigned smarter and unassigned odersky Jun 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants