Created
March 29, 2015 06:01
-
-
Save dragisak/10a3a5837662cdaa29db to your computer and use it in GitHub Desktop.
Type level programming in Scala: Heterogeneous list
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
package com.dragisak.hlist | |
object HList { | |
sealed trait HList { | |
type prepend[A] <: HList | |
def ::[A](a: A) :prepend[A] | |
} | |
case class HCons[H, Tail <: HList](head: H, tail: Tail) extends HList { | |
override type prepend[A] = HCons[A, HCons[H, Tail]] | |
override def ::[A](a: A): prepend[A] = HCons(a, this) | |
} | |
case object HNil extends HList { | |
override type prepend[A] = HCons[A, HNil.type ] | |
override def ::[A](a: A): prepend[A] = HCons(a, this) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice! Thank you!