Skip to content

Instantly share code, notes, and snippets.

@ramn
Created July 8, 2013 23:08
Show Gist options
  • Save ramn/5953260 to your computer and use it in GitHub Desktop.
Save ramn/5953260 to your computer and use it in GitHub Desktop.
HList in Scala (v1 from Scala in depth)
// HList implementation
sealed trait HList
final case class HCons[H, T <: HList](head: H, tail: T) extends HList {
def ::[T](v : T) = HCons(v,this)
override def toString = head + " :: " + tail
}
final class HNil extends HList {
def ::[T](v : T) = HCons(v,this)
override def toString = "Nil"
}
object HList {
type ::[H, T <: HList] = HCons[H,T]
val :: = HCons
val HNil = new HNil
}
// Used as such:
import HList._
val x = "Hi" :: 5 :: false :: HNil
val one :: two :: three :: HNil = x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment