I'm building a parse library that has functions with differing parameter requirements and am modeling as follows. The compiler throws the constructor cannot be instantiated to expected type error on the match.
Any help appreciated
class InstructionType[+A](name: String, params: Int) {
def paramCount = params
def executeInstruction[A](params: String*) = {
this match {
case OneParam(_, fn) => fn(Register(params(0)))
case TwoParamRegRef(_, fn) => fn(Register(params(0)), isValue(params(0)))
case TwoParamRefRef(_, fn) => fn(isValue(params(0)), isValue(params(0)))
}
}
}
case class OneParam(name: String, fn: Register => Unit) extends InstructionTypeRegister => Unit { def getInstruction = fn }
case class TwoParamRegRef(name: String, fn: (Register, Either[Register, Int]) => Unit) extends InstructionType(Register, Either[Register, Int]) => Unit { def getInstruction = fn }
case class TwoParamRefRef(name: String, fn: (Either[Register, Int], Either[Register, Int]) => Unit) extends InstructionType(Either[Register, Int], Either[Register, Int]) => Unit { def getInstruction = fn }
Aucun commentaire:
Enregistrer un commentaire