8
이 코드에 문제가 있습니다. Elements BinaryOperations 및 UnaryOperations가있는 OperationTree로되어 있습니다. 메소드 eval은 평가를 수행하고 맵에서 변수를 찾습니다.익명 함수의 인수 유형
여기
1 import collection.immutable.HashMap
2 sealed abstract class OpTree[T]{
3
4 def eval(v:HashMap[Char,T]):T = {
5 case Elem(x) => x
6 case UnOp(f,c) => {
7 f(c.eval(v))
8 }
9 case BinOp(f,l,r) => {
10 f(l.eval(v),r.eval(v))
11 }
12 case Var(c) => {
13 v.get(c)
14 }
15 }
16 }
17 //Leaf
18 case class Elem[T](elm:T) extends OpTree[T]
19 //Node with two sons
20 case class UnOp[T](f:T => T, child:OpTree[T]) extends OpTree[T]
21 //Node with one son
22 case class BinOp[T](f:(T,T) => T, left:OpTree[T], right:OpTree[T]) extends OpTree[T]
23 case class Var[T](val c:Char) extends OpTree[T]
컴파일러는 말한다 코드입니다 :
OpTree.scala:4: error: missing parameter type for expanded function
The argument types of an anonymous function must be fully known. (SLS 8.5)
Expected type was: T
def eval(v:HashMap[Char,T]):T = {
^
one error found
어떤 제안 ??
감사합니다. 당신은 실제로 뭔가를 일치에 잊어 버린
알고 당신이 올렸습니다. –
: def eval (v : HashMap [Char, T]) : T = { – xyz