Hello all,

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:

abstract class Shape
case class Point(x: Int, y: Int) extends Shape
case class Polygon(points: Point*) extends Shape

Now suppose that I create a polygon as such:

val poly = new Polygon(Point(7, 3), Point(1, 6), Point(2, 4))

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.

Below are snippets of different attempts and the corresponding error messages that they produce.

val upperLeftX = poly.points.reduceLeft(Math.min(_.x, _.x))

Gives the error:
"missing parameter type for expanded function ((x$1) => x$1.x)"

val upperLeftX = poly.points.reduceLeft((a: Point, b: Point) => (Math.min(a.x, b.x)))

Gives this error:
"type mismatch;
found : (Point, Point) => Int
required: (Any, Point) => Any"

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?

6 Years
Discussion Span
Last Post by ~s.o.s~

> Is this java? It looks like it is some sort of C.

No, it's Scala, an OO-functional language which targets the JVM.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.