Question: In HASKELL: 1. Datatype In 2C, analytic geometry, a circle could be denoted as, for instance. (43.1, 55.0,10.4) where the first and second fields are

In HASKELL:

1. Datatype

In 2C, analytic geometry, a circle could be denoted as, for instance. (43.1, 55.0,10.4) where the first and second fields are the coordinates of the circle, center and the third field is the radius. Similarly, a rectangle could be represented by (x1, y1, x2, y2) where (x1, y1) and (x2 ,y2) are the coordinates of two opposite corners of me rectangle. Let's say that a shape can be a circle or a rectangle: a. Make your own type to represent these shapes.

data Shape =

b. Lets make a function Nat takes a shape and returns its surface. Note that the area of a circle radius r is pi*^r^2 , and that of a rectangle is width*length

surface :: Shape -> Float

c. Assume that we make a data type that defines a point in 2D space: data Point = Point Float Float

Redefine your shape so Nat the center of a circle and the corners of a rectangle are now represented by data Point.

data Shape =

d. Adjust your surface function to reflect these changes.

surface :: Shape -> Float

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!