Last active
February 21, 2021 06:29
-
-
Save xuwei-k/924c69482c972d7bac496922ed725f79 to your computer and use it in GitHub Desktop.
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
scalaVersion := "3.0.0-RC1" |
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
import scala.compiletime.ops.int._ | |
sealed trait HList { | |
def ::[H](head: H): head.type :: this.type = new ::[head.type, this.type](head, this) | |
} | |
final case class ::[+H, +T <: HList](head: H, tail: T) extends HList | |
sealed trait HNil extends HList | |
case object HNil extends HNil | |
object MatchTypeSort { | |
type LTs[A <: HList, B <: Int] <: HList = A match { | |
case HNil => | |
HNil | |
case t :: ts => | |
(t < B) match { | |
case true => | |
t :: LTs[ts, B] | |
case false => | |
LTs[ts, B] | |
} | |
} | |
type GTs[A <: HList, B <: Int] <: HList = A match { | |
case HNil => | |
HNil | |
case t :: ts => | |
(t > B) match { | |
case true => | |
t :: GTs[ts, B] | |
case false => | |
GTs[ts, B] | |
} | |
} | |
def typed[A](a: A): Unit = () | |
type HListConcat[A <: HList, B <: HList] <: HList = A match { | |
case HNil => | |
B | |
case h :: t => | |
h :: (HListConcat[t, B]) | |
} | |
type Sort[A <: HList] <: HList = A match { | |
case HNil => | |
HNil | |
case h :: t => | |
HListConcat[Sort[LTs[t, h]], h :: Sort[GTs[t, h]]] | |
} | |
def main(args: Array[String]): Unit = { | |
typed[Sort[5 :: 3 :: 7 :: 2 :: 1 :: 6 :: 4 :: HNil]]( | |
1 :: 2 :: 3 :: 4 :: 5 :: 6 :: 7 :: (HNil: HNil) | |
) | |
} | |
} |
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
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.5.3") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment