Skip to content

Mysterious type mismatch when playing with higher-kinded implicits #4667

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

Closed
LPTK opened this issue Jun 15, 2018 · 2 comments
Closed

Mysterious type mismatch when playing with higher-kinded implicits #4667

LPTK opened this issue Jun 15, 2018 · 2 comments
Labels
area:typer itype:bug stat:needs minimization Needs a self contained minimization

Comments

@LPTK
Copy link
Contributor

LPTK commented Jun 15, 2018

The problem I mentioned in #2500 (comment).

trait Type { type T }
object Type { implicit def Type[S]: Type { type T = S } = new Type { type T = S } }
trait Type1 { type T[_] }
object Type1 { implicit def Type1[S[_]]: Type1 { type T[A] = S[A] } = new Type1 { type T[A] = S[A] } }
trait Functor[F[_]] { def map[A,B](x: F[A])(f: A => B): F[B] }
object Functor { implicit object listFun extends Functor[List] { def map[A,B](ls: List[A])(f: A => B) = ls.map(f) } }

val map: implicit (A:Type,B:Type,F:Type1) => (F.T[A.T]) => (A.T => B.T) =>
         implicit (Functor[F.T])          => F.T[B.T]
  = x => f => implicit fun => fun.map(x)(f)

val ls = List(1,2,3)
println(map.apply.apply(ls)(_.toString))

gives:

-- Error: /tmp/scastie6141179723275680546/src/main/scala/main.scala:38:43 ------
   |    println(map.apply.apply(ls)(_.toString))
   |                                           ^
   |no implicit argument of type Functor[List] was found for parameter of implicit Functor[List] => List[String]

When calling map.apply.apply(ls)(_.toString)(listFun:Functor[List]) I get the error found: Functor[List]; required: Functor[List] so I assume it's a current Dotty bug.

@abgruszecki
Copy link
Contributor

abgruszecki commented Jan 28, 2019

scala> trait Type { type T }                                                                                                
     | object Type { implicit def Type[S]: Type { type T = S } = new Type { type T = S } }
     | trait Type1 { type T[_] }
     | object Type1 { implicit def Type1[S[_]]: Type1 { type T[A] = S[A] } = new Type1 { type T[A] = S[A] } }
     | trait Functor[F[_]] { def map[A,B](x: F[A])(f: A => B): F[B] }
     | object Functor { implicit object listFun extends Functor[List] { def map[A,B](ls: List[A])(f: A => B) = ls.map(f) } }
     | 
     | val map: implicit (A:Type,B:Type,F:Type1) => (F.T[A.T]) => (A.T => B.T) =>
     |          implicit (Functor[F.T])          => F.T[B.T]
     |   = x => f => implicit fun => fun.map(x)(f)
     | 
     | val ls = List(1,2,3)
     | println(map.apply.apply(ls)(_.toString)(Functor.listFun: Functor[List]))
13 |println(map.apply.apply(ls)(_.toString)(Functor.listFun: Functor[List]))
   |                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |                                        Found:    Functor[List]
   |                                        Required: Functor[List]

@smarter ^ this looks kind of terrifying, pretty sure we should do something about it. Probably needs more minimalisation as well.

@abgruszecki abgruszecki added the stat:needs minimization Needs a self contained minimization label Jan 28, 2019
@odersky odersky closed this as completed Mar 8, 2020
@abgruszecki
Copy link
Contributor

Tested the above example, works on current master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:typer itype:bug stat:needs minimization Needs a self contained minimization
Projects
None yet
Development

No branches or pull requests

4 participants