2012-04-27 40 views
0

我有一些代碼,說在Foo.scala編譯容易scalac, 但我得到了一個暴風雪的錯誤,當我啓動REPL並說:load Foo.scala。 我想這是標準和記錄,但似乎無法找到任何相關的 有關它的信息。代碼與scalac編譯但不是在REPL

文件看起來是這樣的:

abstract class BST[A](implicit cmp: A => Ordered[A]) { 
    def fold[B](f: (B, A) => B, acc: B): B = { 
    this match { 
     case Leaf()  => acc 
    }     
    } 
} 

case class Leaf[A]()(implicit cmp: A => Ordered[A]) extends BST[A] 

而且我得到的錯誤,像這樣:

scala> :load BST3.scala 
Loading BST3.scala... 
<console>:10: error: constructor cannot be instantiated to expected type; 
found : Leaf[A(in class Leaf)] 
required: BST[A(in class BST)] 
      case Leaf()  => acc 
       ^

回答

2

它看起來像:load試圖解釋文件塊逐塊。由於你的塊是相互依賴的,這是一個問題。

嘗試使用「粘貼模式」,以多塊粘貼到REPL斯卡拉編譯在一起:

scala> :paste 

// Entering paste mode (ctrl-D to finish) 

abstract class BST[A](implicit cmp: A => Ordered[A]) { 
    def fold[B](f: (B, A) => B, acc: B): B = { 
    this match { 
     case Leaf()  => acc 
    }     
    } 
} 

case class Leaf[A]()(implicit cmp: A => Ordered[A]) extends BST[A] 

// Exiting paste mode, now interpreting. 

defined class BST 
defined class Leaf 
+0

謝謝你的提示重新:粘貼模式! – 2012-04-27 04:39:43