As :help
says,
:load
load and interpret a Scala file
it loads file and interprets it line-by-line, just like it would interpret individual lines that you feed to REPL, whereas :paste interpret whole chunk of code as an atomical unit.
The error, as you can predict is that repl sees
abstract class AExp {
def eval : Int = this match {
case Num(n) => n
case Add(e1, e2) => e1.eval + e2.eval
}
}
But know nothing about Num and Add types -- they aren't defined yet. The trick to make :load work the way you wanted to is to wrap all your code in some super object, e.g.:
object InterpretAsUnit {
// all your code goes there
}
P.S.
funny fact, is that scala -i <your path>
nearly identical to scala
and then :load <your path>