Created
April 25, 2017 15:44
-
-
Save olafurpg/815ddd1fee10e385d17c8a9dbfd40c52 to your computer and use it in GitHub Desktop.
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
import scala.language.higherKinds | |
object hlists { | |
sealed abstract class HList { | |
type Merge[L <: HList] <: HList | |
def merge[L <: HList](l: L): Merge[L] | |
} | |
final case class HCons[H, T <: HList](head : H, tail : T) extends HList { | |
type Merge[L <: HList] = HCons[H, tail.Merge[L]] | |
def merge[L <: HList](l: L): Merge[L] = HCons(head, tail.merge(l)) | |
} | |
sealed trait HNil extends HList { | |
type Merge[L <: HList] = L | |
def merge[L <: HList](l: L): Merge[L] = l | |
} | |
final val HNil: HNil = { case object HNil extends HNil; HNil } | |
} | |
object test { | |
import hlists._ | |
val merged: HCons[Int,HCons[String,HNil]] = HCons(42, HNil) merge HCons("foo", HNil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment