If the T is unknown, then compilation on the fly is handled handily:
apm@mara:~/goof$ scalam -cp /tmp
Welcome to Scala version 2.11.0-M7 (OpenJDK 64-Bit Server VM, Java 1.7.0_25).
Type in expressions to have them evaluated.
Type :help for more information.
scala> new ts.X {}
res0: ts.X = $anon$1@13ba518f
scala> import tools.reflect.ToolBox
import tools.reflect.ToolBox
scala> import reflect.runtime._
import reflect.runtime._
scala> import universe._
import universe._
scala> val tb = currentMirror.mkToolBox()
tb: scala.tools.reflect.ToolBox[reflect.runtime.universe.type] = scala.tools.reflect.ToolBoxFactory$ToolBoxImpl@62920919
scala> tb.eval(tb.parse("new ts.X with ts.Y {}"))
res2: Any = __wrapper$1$88859f071ea8497cb9bf4b87aa027c85.__wrapper$1$88859f071ea8497cb9bf4b87aa027c85$$anon$1@5fa8881b
scala> res2.asInstanceOf[ts.X with ts.Y]
res3: ts.X with ts.Y = __wrapper$1$88859f071ea8497cb9bf4b87aa027c85.__wrapper$1$88859f071ea8497cb9bf4b87aa027c85$$anon$1@5fa8881b
There is an issue to make REPL-compiled classes visible to the toolbox.
For now, roll your own:
scala> val rtm = runtimeMirror($intp.classLoader)
rtm: reflect.runtime.universe.Mirror = JavaMirror with scala.tools.nsc.interpreter.IMain$TranslatingClassLoader@5349c9cb of type class scala.tools.nsc.interpreter.IMain$TranslatingClassLoader with classpath [(memory)] and parent being scala.reflect.internal.util.ScalaClassLoader$URLClassLoader@115f5925 of type class scala.reflect.internal.util.ScalaClassLoader$URLClassLoader with classpath [file:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/resources.jar,file:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/rt.jar,file:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/jsse.jar,file:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/jce.jar,file:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/charsets.jar,file:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/rhino.jar,file:/home/apm/scala-2.11.0-M7/lib/akka-actors.jar,file:/hom...
scala> val rtb = rtm.mkToolBox()
rtb: scala.tools.reflect.ToolBox[reflect.runtime.universe.type] = scala.tools.reflect.ToolBoxFactory$ToolBoxImpl@58f59add
scala> :pa -raw
// Entering paste mode (ctrl-D to finish)
package foo
class Foo
// Exiting paste mode, now interpreting.
scala> rtb.eval(rtb.parse("new foo.Foo"))
res6: Any = foo.Foo@7c20db7f
xalready extended theAtrait, obviating the need to add the inheritance?