I have done a few implementations of HList now. One based on Daniel Spiewak\'s High Wizardry in the Land of Scala talk and another based on a post in Apocalisp blog. The goal
what you need is a Klist with type constructor Request
, and a natural transformation execute: Request ~> Id
. All of this is detailed in the marvelous type-level programming series of posts at Apocalisp, in particular:
you can checkout the code for the whole series from Mark Harrah's up repo
In your case, you'll need something like
val reqList = new Request[Int](1) :^: new Request[String]("1") :^: KNil
val exec = new (Request ~> Id) { def apply[T](reqs: Request[T]): T = reqs.execute }
val results = reqList down exec
the down
method above is conceptually the same as map
for a nat transf M ~> Id
; you also have more general map
which from a nat transf M ~> N
and a Klist of kind M yields a KList of kind N.