Quantcast
Channel: Haskell usage of data type - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Answer by Thomas M. DuBuisson for Haskell usage of data type

$
0
0

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.


Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>