 # Classes's relation based on Union types

There are one base class State and classes and their relations :
class A , B, C, D and possible relations :
A , B, B -> C , A -> C, C -> D, B -> D
A based on Nothing
B based on Nothing
C based on A OR B
D based on A OR B OR С

After some research i’ve found article about curry-howard isomorphism , it helps to implement union types.
So i want to improve this ugly implementation :

``````type ![S] = S => Nothing
type !![S] = ![![S]]
type ∨[T, U] = ![![T] with ![U]]
type |∨|[T, U] = {type λ[X] = !![X] <:< (T ∨ U)}

trait State { type T <: State }

case class A() extends State
case class B() extends State
case class C(state: State) extends State {
def apply[T<: State](state: T)(implicit ctx: (A |∨| B)#λ[state.T]) = C(state)
}
case class D(state: State) {
def apply[T<: State](state: T)(implicit ctx: (A |∨| B |∨| C)#λ[state.T]) = D(state)
}

val a = A(); val b = B()
val ca = C(a); val cb = C(b)
val dc = D(ca); val da = D(a)
``````

Could someone suggests better implementation, without explicit declaration of apply method in each class ?