1

I can do following easily with Dotty:

trait Ex {type T <: Int | Seq[Int]; def f:T}

trait Ex2 extends Ex {override type T = Seq[Int]; override def f = Seq(2)}

trait Ex3 extends Ex {override type T = Int; override def f = 2}

How can I do union type subtyping without Dotty?

  • My question is quite different from "how to implement everything you can do with dotty without dotty". – Alexander Chepurnoy Jul 06 '16 at 17:35
  • Type disjunctions are already hard, but I imagine you could make subtypes work if you hated yourself enough: http://stackoverflow.com/questions/3508077/how-to-define-type-disjunction-union-types/21054507 – J Cracknell Jul 07 '16 at 05:56

1 Answers1

1

The simple solution is the upper bound type:

trait Ex {type T >: Int with Seq[Int]; def f:T}

trait Ex2 extends Ex {override type T = Seq[Int]; override def f = Seq(2)}

trait Ex3 extends Ex {override type T = Int; override def f = 2}