Skip to content

Instantly share code, notes, and snippets.

@EECOLOR
Created October 5, 2014 11:31
Show Gist options
  • Save EECOLOR/3446d8a6defa22b25ea6 to your computer and use it in GitHub Desktop.
Save EECOLOR/3446d8a6defa22b25ea6 to your computer and use it in GitHub Desktop.
Clean construction of coproducts
trait Co[F[_], G[_]] {
case class Product[A](value: Either[F[A], G[A]])
}
trait ProgramType[F[_]]
object ProgramType {
def apply[T](implicit to: ToParameterized[T]): ProgramType[to.Out] = ???
}
trait ToParameterized[T] {
type Out[_]
}
object ToParameterized {
implicit def withEmpty[F[_]]:ToParameterized[F +: Nil] {
type Out[A] = F[A]
} = null
implicit def typeSet[F[_], G[_], X](
implicit to: ToParameterized[G +: X]):ToParameterized[F +: G +: X] {
type Out[A] = Co[F, to.Out]#Product[A]
} = null
}
trait +:[F[_], Types]
trait Nil
implicit val programType = ProgramType[Store +: Json +: Utilities +: Nil]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment