Skip to content

Commit 324044e

Browse files
committed
New type lambda scheme for hk types
1 parent 1e6b0cf commit 324044e

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/dotty/tools/dotc/config/Config.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ object Config {
88
final val cacheMemberNames = true
99
final val cacheImplicitScopes = true
1010

11+
final val newHK = false
12+
1113
final val checkCacheMembersNamed = false
1214

1315
/** When updating a constraint bound, check that the constrained parameter

src/dotty/tools/dotc/core/TypeApplications.scala

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,35 @@ import StdNames.tpnme
1515
import util.Positions.Position
1616
import config.Printers._
1717
import collection.mutable
18+
import dotty.tools.dotc.config.Config
1819
import java.util.NoSuchElementException
1920

21+
object TypeApplicationsNewHK {
22+
import TypeApplications._
23+
24+
object TypeLambda {
25+
def apply(argBindingFns: List[RefinedType => TypeBounds],
26+
bodyFn: RefinedType => Type)(implicit ctx: Context): Type = {
27+
val argNames = argBindingFns.indices.toList.map(tpnme.hkArg)
28+
RefinedType.recursive(bodyFn, argNames, argBindingFns)
29+
}
30+
31+
def unapply(tp: Type)(implicit ctx: Context): Option[(List[TypeBounds], Type)] = {
32+
def decompose(t: Type, acc: List[TypeBounds]): (List[TypeBounds], Type) = t match {
33+
case t @ RefinedType(p, rname, rinfo: TypeBounds)
34+
if rname.isHkArgName && rinfo.isBinding =>
35+
decompose(p, rinfo.bounds :: acc)
36+
case _ =>
37+
(acc, t)
38+
}
39+
decompose(tp, Nil) match {
40+
case (Nil, _) => None
41+
case x => Some(x)
42+
}
43+
}
44+
}
45+
}
46+
2047
object TypeApplications {
2148

2249
/** Assert type is not a TypeBounds instance and return it unchanged */
@@ -51,6 +78,14 @@ object TypeApplications {
5178
* [v1 X1: B1, ..., vn Xn: Bn] -> T
5279
* ==>
5380
* ([X_i := this.$hk_i] T) { type v_i $hk_i: (new)B_i }
81+
*
82+
* [X] -> List[X]
83+
*
84+
* List { type List$A = this.$hk_0 } { type $hk_0 }
85+
*
86+
* [X] -> X
87+
*
88+
* mu(this) this.$hk_0 & { type $hk_0 }
5489
*/
5590
object TypeLambda {
5691
def apply(variances: List[Int],

0 commit comments

Comments
 (0)