Skip to content

Instantly share code, notes, and snippets.

@mmenestret
Created February 28, 2019 15:36
Show Gist options
  • Save mmenestret/f417287b20dcd19bd8ecc0308add8e56 to your computer and use it in GitHub Desktop.
Save mmenestret/f417287b20dcd19bd8ecc0308add8e56 to your computer and use it in GitHub Desktop.
object EnvEffetWithoutSubtyping {
import EnvEffetWithoutSubtyping.Alg1.HasAlg1
import EnvEffetWithoutSubtyping.Alg2.HasAlg2
import EnvEffetWithoutSubtyping.Alg3.HasAlg3
trait Alg1
object Alg1 {
trait HasAlg1[E] {
def alg1(e: E): Alg1
}
}
trait Alg2
object Alg2 {
trait HasAlg2[E] {
def alg2(e: E): Alg2
}
}
trait Alg3
object Alg3 {
trait HasAlg3[E] {
def alg3(e: E): Alg3
}
}
final case class SmallEnv(alg1: Alg1, alg2: Alg2)
object SmallEnv {
implicit val env1: HasAlg1[SmallEnv] = _.alg1
implicit val env2: HasAlg2[SmallEnv] = _.alg2
}
final case class BigEnv(alg1: Alg1, alg2: Alg2, alg3: Alg3)
object BigEnv {
implicit val env1: HasAlg1[BigEnv] = _.alg1
implicit val env2: HasAlg2[BigEnv] = _.alg2
implicit val env3: HasAlg3[BigEnv] = _.alg3
}
def program[Env: HasAlg1: HasAlg2: HasAlg3](): Kleisli[Id, Env, Unit] = {
def innerF1[InnerEnv: HasAlg1]: Reader[InnerEnv, Unit] = ???
def innerF2[InnerEnv: HasAlg2]: Reader[InnerEnv, Unit] = ???
def innerF3[InnerEnv: HasAlg1: HasAlg2]: Reader[InnerEnv, Unit] = ???
def innerF4[InnerEnv: HasAlg1: HasAlg2: HasAlg3]: Reader[InnerEnv, Unit] = ???
for {
_ <- innerF1
_ <- innerF2
_ <- innerF3
_ <- innerF4
} yield ()
}
program[BigEnv]()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment