forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement match type amendment: extractors follow aliases and singletons
This implements the change proposed in scala/improvement-proposals#84. The added pos test case presents motivating examples, the added neg test cases demonstrate that errors are correctly reported when cycles are present. The potential for cycle is no worse than with the existing extraction logic as demonstrated by the existing test in `tests/neg/mt-deskolemize.scala`.
- Loading branch information
Showing
3 changed files
with
145 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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 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,49 @@ | ||
trait Expr: | ||
type Value | ||
|
||
object Expr: | ||
type Of[V] = Expr { type Value = V } | ||
type ExtractValue[F <: Expr] = F match | ||
case Expr.Of[v] => v | ||
import Expr.ExtractValue | ||
|
||
class Prim extends Expr: | ||
type Value = Alias | ||
type Alias = BigInt | ||
|
||
class VecExpr[E <: Expr] extends Expr: | ||
type Value = Vector[ExtractValue[E]] | ||
|
||
trait Description: | ||
type Elem <: Tuple | ||
|
||
trait ProdExpr extends Expr: | ||
val description: Description | ||
type Value = Tuple.Map[description.Elem, [X] =>> ExtractValue[X & Expr]] | ||
|
||
class MyExpr1 extends ProdExpr: | ||
final val description = new Description: | ||
type Elem = (VecExpr[Prim], Prim) | ||
|
||
class MyExpr2 extends ProdExpr: | ||
final val description = new Description: | ||
type Elem = (VecExpr[VecExpr[MyExpr1]], Prim) | ||
|
||
trait ProdExprAlt[T <: Tuple] extends Expr: | ||
type Value = Tuple.Map[T, [X] =>> ExtractValue[X & Expr]] | ||
|
||
class MyExpr3 extends ProdExprAlt[(Prim, VecExpr[Prim], Prim)] | ||
|
||
object Test: | ||
def fromLiteral[E <: Expr](v: ExtractValue[E]): E = ??? | ||
val a: Prim = fromLiteral(1) | ||
val b: VecExpr[Prim] = fromLiteral(Vector(1)) | ||
val c: MyExpr1 = fromLiteral((Vector(1), 1)) | ||
val d: MyExpr2 = fromLiteral(Vector(Vector((Vector(1), 1))), 2) | ||
val e: MyExpr3 = fromLiteral((1, Vector(1), 1)) | ||
val f: ProdExprAlt[(MyExpr1, VecExpr[MyExpr3])] = fromLiteral: | ||
( | ||
(Vector(1), 1), | ||
Vector((1, Vector(1), 1), (2, Vector(1), 2)) | ||
) | ||
val g: Expr { type Alias = Int; type Value = Alias } = fromLiteral(1) |