Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed help figuring out scala compiler errors
    primarykey
    data
    text
    <p>I have been working on a project in scala, but I am getting some error messages that I don't quite understand. The classes that I am working with are relatively simple. For example:</p> <pre><code>abstract class Shape case class Point(x: Int, y: Int) extends Shape case class Polygon(points: Point*) extends Shape </code></pre> <p>Now suppose that I create a Polygon:</p> <pre><code>val poly = new Polygon(new Point(2,5), new Point(7,0), new Point(3,1)) </code></pre> <p>Then if I attempt to determine the location and size of the smallest possible rectangle that could contain the polygon, I get various errors that I don't quite understand.</p> <p>Below are snippets of different attempts and the corresponding error messages that they produce.</p> <pre><code>val upperLeftX = poly.points.reduceLeft(Math.min(_.x, _.x)) </code></pre> <p>Gives the error:<br> "<em>missing parameter type for expanded function ((x$1) => x$1.x)</em>"</p> <pre><code>val upperLeftX = poly.points.reduceLeft((a: Point, b: Point) =&gt; (Math.min(a.x, b.x))) </code></pre> <p>Gives this error:<br> "<em>type mismatch;<br> found : (Point, Point) => Int<br> required: (Any, Point) => Any</em>"</p> <p>I am very confused about both of these error messages. If anyone could explain more clearly what I am doing incorrectly, I would really appreciate it. Yes, I see that the second error says that I need type "Any" but I don't understand exactly how to implement a change that would work as I need it. Obviously simply changing "a: Point" to "a: Any" is not a viable solution, so what am I missing? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload