Created
July 30, 2015 10:48
-
-
Save milessabin/cab5661217ec47bbddad to your computer and use it in GitHub Desktop.
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
import shapeless._, ops.function._, ops.hlist._ | |
trait Bar { | |
trait Wrapper { type T } | |
case class A[U]() extends Wrapper { type T = U } | |
trait Unwrapper { | |
type Args <: HList | |
type F[R] = Args => R | |
} | |
object Unwrapper { | |
type Aux[A] = Unwrapper { type Args = A } | |
implicit def mkUnwrapper[P <: Product, L <: HList, UL <: HList](p: P) | |
(implicit gen: Generic.Aux[P, L], ul: ReprUnwrapper.Aux[L, UL]): Aux[UL] = | |
new Unwrapper { | |
type Args = UL | |
} | |
} | |
trait ReprUnwrapper[P] { | |
type Args <: HList | |
type F[R] = Args => R | |
} | |
object ReprUnwrapper { | |
type Aux[P, A] = ReprUnwrapper[P] { type Args = A } | |
implicit val hnil: Aux[HNil, HNil] = | |
new ReprUnwrapper[HNil] { | |
type Args = HNil | |
} | |
implicit def cons[H <: Wrapper, W[_], UH, T <: HList, UT <: HList] | |
(implicit uh: Unpack1[H, W, UH], ut: ReprUnwrapper.Aux[T, UT]): Aux[H :: T, UH :: UT] = | |
new ReprUnwrapper[H :: T] { | |
type Args = UH :: UT | |
} | |
} | |
implicit def conv[F, P](f: F)(implicit fntop: FnToProduct.Aux[F, P]): P = fntop(f) | |
def getFn[R](u: Unwrapper)(f: u.F[R]) = f | |
} | |
object Bar extends Bar | |
object Test { | |
import Bar._ | |
getFn(A[Int], A[String], A[Boolean]){ (a: Int, b: String, c: Boolean) => 1.0 } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment