Skip to content

Instantly share code, notes, and snippets.

@mossprescott
Created June 15, 2016 22:52
Show Gist options
  • Select an option

  • Save mossprescott/3f49dad5ebc19f45949e7e34d7645b52 to your computer and use it in GitHub Desktop.

Select an option

Save mossprescott/3f49dad5ebc19f45949e7e34d7645b52 to your computer and use it in GitHub Desktop.
Testing performance with Coproduct and `:+:` op
trait T0[A]
trait T1[A]
trait T2[A]
trait T3[A]
trait T4[A]
trait T5[A]
trait T6[A]
trait T7[A]
trait T8[A]
trait T9[A]
trait T10[A]
trait T11[A]
trait T12[A]
trait T13[A]
trait T14[A]
trait T15[A]
trait T16[A]
type T0F[A] = Coyoneda[T0, A]
type T1F[A] = Coyoneda[T1, A]
type T2F[A] = Coyoneda[T2, A]
type T3F[A] = Coyoneda[T3, A]
type T4F[A] = Coyoneda[T4, A]
type T5F[A] = Coyoneda[T5, A]
type T6F[A] = Coyoneda[T6, A]
type T7F[A] = Coyoneda[T7, A]
type T8F[A] = Coyoneda[T8, A]
type T9F[A] = Coyoneda[T9, A]
type T10F[A] = Coyoneda[T10, A]
type T11F[A] = Coyoneda[T11, A]
type T12F[A] = Coyoneda[T12, A]
type T13F[A] = Coyoneda[T13, A]
type T14F[A] = Coyoneda[T14, A]
type T15F[A] = Coyoneda[T15, A]
type T16F[A] = Coyoneda[T16, A]
// Right-associative, as required according to the paper:
type RCP0[A] = Coproduct[T1, T0, A]
type RCP1[A] = Coproduct[T2, RCP0, A]
type RCP2[A] = Coproduct[T3, RCP1, A]
type RCP3[A] = Coproduct[T4, RCP2, A]
type RCP4[A] = Coproduct[T5, RCP3, A]
type RCP5[A] = Coproduct[T6, RCP4, A]
type RCP6[A] = Coproduct[T7, RCP5, A]
type RCP7[A] = Coproduct[T8, RCP6, A]
type RCP8[A] = Coproduct[T9, RCP7, A]
type RCP9[A] = Coproduct[T10, RCP8, A]
type RCP10[A] = Coproduct[T11, RCP9, A]
type RCP11[A] = Coproduct[T12, RCP10, A]
type RCP12[A] = Coproduct[T13, RCP11, A]
type RCP13[A] = Coproduct[T14, RCP12, A]
type RCP14[A] = Coproduct[T15, RCP13, A]
type RCP[A] = Coproduct[T16, RCP14, A]
val injR1_1: T1 :<: RCP0 = scala.Predef.implicitly
val injR16: T16 :<: RCP = scala.Predef.implicitly
val injR0: T0 :<: RCP = scala.Predef.implicitly
// Right-associative, as required according to the paper:
type CRCP0[A] = Coproduct[T1F, T0F, A]
type CRCP1[A] = Coproduct[T2F, CRCP0, A]
type CRCP2[A] = Coproduct[T3F, CRCP1, A]
type CRCP3[A] = Coproduct[T4F, CRCP2, A]
type CRCP4[A] = Coproduct[T5F, CRCP3, A]
type CRCP5[A] = Coproduct[T6F, CRCP4, A]
type CRCP6[A] = Coproduct[T7F, CRCP5, A]
type CRCP7[A] = Coproduct[T8F, CRCP6, A]
type CRCP8[A] = Coproduct[T9F, CRCP7, A]
type CRCP9[A] = Coproduct[T10F, CRCP8, A]
type CRCP10[A] = Coproduct[T11F, CRCP9, A]
type CRCP11[A] = Coproduct[T12F, CRCP10, A]
type CRCP12[A] = Coproduct[T13F, CRCP11, A]
type CRCP13[A] = Coproduct[T14F, CRCP12, A]
type CRCP14[A] = Coproduct[T15F, CRCP13, A]
type CRCP[A] = Coproduct[T16F, CRCP14, A]
val injCR1_1: T1F :<: CRCP0 = scala.Predef.implicitly
val injCR16: T16F :<: CRCP = scala.Predef.implicitly
val injCR0: T0F :<: CRCP = scala.Predef.implicitly
type Op[A] = (T16 :+: (T15 :+: (T14 :+: (T13 :+:
(T12 :+: (T11 :+: (T10 :+: (T9 :+:
(T8 :+: (T7 :+: (T6 :+: (T5 :+:
(T4 :+: (T3 :+: (T2 :+: (T1 :+: T0)
#λ)#λ)#λ)#λ)
#λ)#λ)#λ)#λ)
#λ)#λ)#λ)#λ)
#λ)#λ)#λ)#λ[A]
val injOp16: T16 :<: Op = scala.Predef.implicitly
// val injOp0: T0 :<: Op = scala.Predef.implicitly // Error
type COp[A] = (T16F :+:
(T15F :+: (T14F :+: (T13F :+: (T12F :+:
(T11F :+: (T10F :+: (T9F :+: (T8F :+:
(T7F :+: (T6F :+: (T5F :+: (T4F :+:
(T3F :+: (T2F :+: (T1F :+: T0F)
#λ)#λ)#λ)#λ)
#λ)#λ)#λ)#λ)
#λ)#λ)#λ)#λ)
#λ)#λ)#λ)#λ[A]
// val injCOp16: T16F :<: COp = scala.Predef.implicitly
// val injCOp16a: T16F :<: COp = scala.Predef.implicitly // 8 seconds
// val injCOp16b: T16F :<: COp = scala.Predef.implicitly // 8 seconds
// val injCOp16c: T16F :<: COp = scala.Predef.implicitly // 8 seconds
// val injCOp16d: T16F :<: COp = scala.Predef.implicitly // 8 seconds
// val injCOp16e: T16F :<: COp = scala.Predef.implicitly // 8 seconds
// val injCOp0: T0F :<: COp = scala.Predef.implicitly // 6 seconds
// val injCOp0a: T0F :<: COp = scala.Predef.implicitly // 6 seconds
// val injCOp0b: T0F :<: COp = scala.Predef.implicitly // 6 seconds
// val injCOp0c: T0F :<: COp = scala.Predef.implicitly // 6 seconds
// val injCOp0d: T0F :<: COp = scala.Predef.implicitly // 6 seconds
// val injCOp0e: T0F :<: COp = scala.Predef.implicitly // 6 seconds
// val inj1_Bar: Bar :<: CP1 = scala.Predef.implicitly
// val inj1_Baz: Baz :<: CP1 = scala.Predef.implicitly
// Left-associative (doesn't work according to the paper)
// type CP2_0[A] = Coproduct[Foo, Bar, A]
// type CP2[A] = Coproduct[CP2_0, Baz, A]
// // val inj2_Foo: Foo :<: CP2 = scala.Predef.implicitly // not found
// // val inj2_Bar: Bar :<: CP2 = scala.Predef.implicitly // not found
// val inj2_Baz: Baz :<: CP2 = scala.Predef.implicitly
// TODO: stack of 14 types
// TODO: define with quasar.fp.:+:
// inject at different levels?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment