Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enumerate subtypes by approximating type skolems to their upper bound
- Loading branch information
Showing
2 changed files
with
31 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// scalac: -Werror | ||
sealed trait PowerSource | ||
case object Petrol extends PowerSource | ||
case object Pedal extends PowerSource | ||
|
||
sealed abstract class Vehicle { type A <: PowerSource } | ||
case object Bicycle extends Vehicle { type A = Pedal.type } | ||
case class Bus(fuel: Int) extends Vehicle { type A = Petrol.type } | ||
case class Car(fuel: Int) extends Vehicle { type A = Petrol.type } | ||
|
||
object Test { | ||
def refuel[P <: Petrol.type](vehicle: Vehicle { type A = P }): Vehicle = vehicle match { | ||
case Car(_) => Car(100) | ||
case Bus(_) => Bus(100) // was: "unreachable code" warning | ||
} | ||
|
||
def main(args: Array[String]): Unit = { | ||
println(refuel(Car(100))) | ||
println(refuel(Bus(5))) | ||
} | ||
} |