In surface
(Rectangle (Point x1 y1) (Point x2 y2))
, we indicate the parameters for Rectangle are of type Point.
No. This is your misconception. The compiler knows the type of Rectangle
's arguments because of the data declaration:
data ... | Rectangle Point Point
In the code you were referencing:
surface (Rectangle (Point x1 y1) (Point x2 y2))
That is called a pattern match. Surface takes a rectangle, which we pattern match in order to bind variable names to the parameters. We also pattern match on each parameter to gain access to the sub-parameters and bind the variable names x1
, y1
, x2
, and y2
.