Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question is about Haskell. All solutions must be in Haskell. Exercise 3. Programming with Data Types Here is the definition of a data type for

Question is about Haskell. All solutions must be in Haskell.

image text in transcribed

image text in transcribed

Exercise 3. Programming with Data Types Here is the definition of a data type for representing a few basic shapes. A figure is a collection of shapes. The type BBox represents bounding boxes of objects by the points of the lower-left and upper-right hand corners of the smallest enclosing rectangle. type Number = Int type Point = (Number, Number) type Length = Number data Shape = Pt Point | Circle Point Length Rect Point Length Length deriving Show type Figure = (Shape) type BBox = (Point, Point) (a) Define the function width that computes the width of a shape. width :: Shape -> Length For example, the widths of the shapes in the figure f are as follows. f = [Pt (4,4), Circle (5,5) 3, Rect (3,3) 7 2] > map widthf [0,6,7] (b) Define the function bbox that computes the bounding box of a shape. bbox :: Shape -> BBox The bounding boxes of the shapes in the figure f are as follows. > map bbox f [((4,4),(4,4)), ((2, 2), (8,8)), ((3,3), (10,5))] (c) Define the function minx that computes the minimum x coordinate of a shape. minx :: Shape -> Number The minimum x coordinates of the shapes in the figure f are as follows. > map minX f [4,2,3] (d) Define a function move that moves the position of a shape by a vector given by a point as its second argument. move :: Shape -> Point -> Shape It is probably a good idea to define and use an auxiliary function addPt :: Point -> Point -> Point, which adds two points component wise

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 19 21 2012 Proceedings Part 3 Lnai 7198

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284922, 978-3642284922

More Books

Students also viewed these Databases questions