fork(1) download
  1. object Main extends App {
  2.  
  3. trait VirtualMachine[A] {
  4. def compile: A
  5. def run: A => Unit
  6. }
  7.  
  8. case class SimpleVirtualMachine[A](compile: A, run: A => Unit)
  9. extends VirtualMachine[A]
  10.  
  11. def helloWorldVM(s: String) = SimpleVirtualMachine(s, println)
  12. def intVM(i: Int) = SimpleVirtualMachine(i, println)
  13. def compileAndRun(vm: VirtualMachine[A forSome {type A}]) {
  14. vm.run(vm.compile)
  15. }
  16. compileAndRun(intVM(1))
  17. }
  18.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.scala:16: error: type mismatch;
 found   : Main.SimpleVirtualMachine[Int]
 required: Main.VirtualMachine[A forSome { type A }]
Note: Int <: A forSome { type A }, but trait VirtualMachine is invariant in type A.
You may wish to define A as +A instead. (SLS 4.5)
  compileAndRun(intVM(1))
                     ^
one error found
spoj: The program compiled successfully, but Main.class was not found.
      Class Main should contain method: def main(args: Array[String]).
stdout
Standard output is empty