Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
pp:2026:scala:l03 [2026/03/11 11:28]
ldaniel
pp:2026:scala:l03 [2026/03/26 07:30] (current)
ldaniel sealed la binaryTree
Line 11: Line 11:
 This definition has already been implemented in Scala, as shown below. Please copy-paste this definition in your worksheet. This definition has already been implemented in Scala, as shown below. Please copy-paste this definition in your worksheet.
 <code scala> <code scala>
-trait IList +sealed ​trait IList 
 case object Void extends IList case object Void extends IList
 case class Cons(x: Int, xs: IList) extends IList case class Cons(x: Int, xs: IList) extends IList
 </​code>​ </​code>​
 +''​! Hint:''​ We use the keyword ''​sealed''​ to specify that all posible implementations of a trait are in the current file (here, Void and Cons for IList).
  
 **3.1.1.** Consider the following axioms for the operator ''​isEmpty''​. **3.1.1.** Consider the following axioms for the operator ''​isEmpty''​.
Line 94: Line 95:
 The binary tree type definition for Scala is given below. Please copy-paste this definition in your Main.scala file from your laboratory project, in order for printTree to work properly. Call print from the function main and click the "​run"​ text above the definition of main to see the result in terminal. The binary tree type definition for Scala is given below. Please copy-paste this definition in your Main.scala file from your laboratory project, in order for printTree to work properly. Call print from the function main and click the "​run"​ text above the definition of main to see the result in terminal.
 <code scala> <code scala>
-trait BinaryTree {+sealed ​trait BinaryTree {
     override def toString: String = super.toString:​ String     override def toString: String = super.toString:​ String
 } }