Created
April 25, 2017 15:44
-
-
Save olafurpg/eb28b1da1556a79bc631f0e4e9ee7a04 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: hlists.HCons[Int,hlists.HCons[String,hlists.HNil]] = hlists.HCons.apply[Int, hlists.HNil](42, hlists.HNil).merge[hlists.HCons[String,hlists.HNil]](hlists.HCons.apply[String, hlists.HNil]("foo", hlists.HNil)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment