-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Preserve HKTypeLambdas representing kinds in wildApprox #6240
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
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
object K1 { | ||
class Foo[T] | ||
|
||
class Bar[F[_]] | ||
object Bar { | ||
implicit def barF[F[_]](implicit fooF: Foo[Bar[F]]): Bar[F] = null | ||
} | ||
|
||
class A[T] | ||
object A { | ||
implicit def fooA[F[_[_]]](implicit barB: F[B]): Foo[F[A]] = null | ||
} | ||
|
||
class B[T] | ||
object B { | ||
implicit def fooB[F[_[_]]]: Foo[F[B]] = null | ||
} | ||
} | ||
|
||
object K1U { | ||
class Foo[T] | ||
|
||
class Bar[F[_ <: Int]] | ||
object Bar { | ||
implicit def barF[F[_ <: Int]](implicit fooF: Foo[Bar[F]]): Bar[F] = null | ||
} | ||
|
||
class A[T <: Int] | ||
object A { | ||
implicit def fooA[F[_[_ <: Int]]](implicit barB: F[B]): Foo[F[A]] = null | ||
} | ||
|
||
class B[T <: Int] | ||
object B { | ||
implicit def fooB[F[_[_ <: Int]]]: Foo[F[B]] = null | ||
} | ||
} | ||
|
||
object K1L { | ||
class Foo[T] | ||
|
||
class Bar[F[_ >: Int]] | ||
object Bar { | ||
implicit def barF[F[_ >: Int]](implicit fooF: Foo[Bar[F]]): Bar[F] = null | ||
} | ||
|
||
class A[T >: Int] | ||
object A { | ||
implicit def fooA[F[_[_ >: Int]]](implicit barB: F[B]): Foo[F[A]] = null | ||
} | ||
|
||
class B[T >: Int] | ||
object B { | ||
implicit def fooB[F[_[_ >: Int]]]: Foo[F[B]] = null | ||
} | ||
} | ||
|
||
object K11 { | ||
class Foo[T] | ||
|
||
class Bar[F[_[_]]] | ||
object Bar { | ||
implicit def barF[F[_[_]]](implicit fooF: Foo[Bar[F]]): Bar[F] = null | ||
} | ||
|
||
class A[T[_]] | ||
object A { | ||
implicit def fooA[F[_[_[_]]]](implicit barB: F[B]): Foo[F[A]] = null | ||
} | ||
|
||
class B[T[_]] | ||
object B { | ||
implicit def fooB[F[_[_[_]]]]: Foo[F[B]] = null | ||
} | ||
} | ||
|
||
object K2 { | ||
class Foo[T] | ||
|
||
class Bar[F[_, _]] | ||
object Bar { | ||
implicit def barF[F[_, _]](implicit fooF: Foo[Bar[F]]): Bar[F] = null | ||
} | ||
|
||
class A[T, U] | ||
object A { | ||
implicit def fooA[F[_[_, _]]](implicit barB: F[B]): Foo[F[A]] = null | ||
} | ||
|
||
class B[T, U] | ||
object B { | ||
implicit def fooB[F[_[_, _]]]: Foo[F[B]] = null | ||
} | ||
} | ||
|
||
object Test { | ||
{ | ||
import K1._ | ||
implicitly[Bar[A]] | ||
} | ||
|
||
{ | ||
import K1U._ | ||
implicitly[Bar[A]] | ||
} | ||
|
||
{ | ||
import K1L._ | ||
implicitly[Bar[A]] | ||
} | ||
|
||
{ | ||
import K11._ | ||
implicitly[Bar[A]] | ||
} | ||
|
||
{ | ||
import K2._ | ||
implicitly[Bar[A]] | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
object Utils { | ||
type Id[t] = t | ||
type Const[c] = [t] => c | ||
} | ||
|
||
import Utils._ | ||
|
||
abstract class ErasedInstances { type FT } | ||
class ErasedProductInstances(override val toString: String) extends ErasedInstances | ||
class ErasedCoproductInstances(override val toString: String) extends ErasedInstances | ||
|
||
object K1 { | ||
type Instances[F[_[_]], T[_]] = ErasedInstances { type FT = F[T] ; type C = F } | ||
} | ||
|
||
class Functor[F[_]](override val toString: String) | ||
|
||
object Functor { | ||
inline def apply[F[_]](implicit ff: Functor[F]): Functor[F] = ff | ||
|
||
implicit val functorId: Functor[Id] = new Functor("functorId") | ||
|
||
implicit def functorNested[F[_], G[_]](implicit ff: Functor[F], fg: Functor[G]): Functor[[t] => F[G[t]]] = new Functor(s"functorNested($ff, $fg)") | ||
|
||
implicit def functorGen[F[_]](implicit inst: K1.Instances[Functor, F]): Functor[F] = new Functor(s"functorGen($inst") | ||
|
||
implicit def functorConst[T]: Functor[Const[T]] = new Functor(s"functorConst") | ||
} | ||
|
||
sealed trait Opt[+A] | ||
object Opt { | ||
implicit def optInstances[F[_[_]]](implicit fs: F[Sm], fn: F[[t] => Nn.type]): ErasedCoproductInstances { type FT = F[Opt] ; type C = F } = | ||
new ErasedCoproductInstances(s"optInstances($fs, $fn)") { type FT = F[Opt] ; type C = F } | ||
} | ||
|
||
case class Sm[+A](value: A) extends Opt[A] | ||
object Sm { | ||
implicit def smInstances[F[_[_]]](implicit fi: F[Id]): ErasedProductInstances { type FT = F[Sm] ; type C = F } = | ||
new ErasedProductInstances(s"smInstances($fi)") { type FT = F[Sm] ; type C = F } | ||
} | ||
|
||
case object Nn extends Opt[Nothing] | ||
|
||
object Test extends App { | ||
assert(Functor[Const[Nn.type]].toString == "functorConst") | ||
assert(Functor[Sm].toString == "functorGen(smInstances(functorId)") | ||
assert(Functor[Opt].toString == "functorGen(optInstances(functorGen(smInstances(functorId), functorConst)") | ||
assert(Functor[[t] => Opt[Opt[t]]].toString == "functorNested(functorGen(optInstances(functorGen(smInstances(functorId), functorConst), functorGen(optInstances(functorGen(smInstances(functorId), functorConst))") | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to have some explanations about the logic here as a comment. In particular I did not understand why a fully defined bounds represents a kind.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am also worried about performance implications.
isFullyDefined
is not cheap, andwildApprox
is a hotspot.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't
isKindBound
also need to returntrue
forAnyKind
? If not, we could use a comment explaining why that's the case.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just finishing up with a different approach ... no need to continue reviewing this.