Last active
August 29, 2015 14:10
-
-
Save mariusdanciu/18e087b5dfee9c4fbd6f to your computer and use it in GitHub Desktop.
HList curry
This file contains 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
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