Skip to content

Instantly share code, notes, and snippets.

@mariusdanciu
Last active August 29, 2015 14:10
Show Gist options
  • Save mariusdanciu/18e087b5dfee9c4fbd6f to your computer and use it in GitHub Desktop.
Save mariusdanciu/18e087b5dfee9c4fbd6f to your computer and use it in GitHub Desktop.
HList curry
object Start extends App {
val l = 1 :: "s" :: HNil
val res = l.run{i => s => i+s}
println(res)
}
trait HList {
type F[R]
def run[R](f: F[R]) : R
}
case class HCons[H, T <: HList](h: H, tail: T) extends HList {
type F[R] = H => (tail.type)#F[R]
def ::[A](h: A) = HCons(h, this)
def run[R](f: F[R]): R = tail.run(f(h))
}
case object HNil extends HList {
type F[R] = R
def ::[A](h: A) = HCons(h, this)
def run[R](f: F[R]): R = f
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment