Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please write code in Haskell and do only (b) We can represent a two dimensional (sparse) array of characters in Haskell as a list of

please write code in Haskell and do only (b) image text in transcribed
We can represent a two dimensional (sparse) array of characters in Haskell as a list of pairs of the form ((r,c),char) where r and c are integers representing the row and column where char appears. If a row-column pair does not appear, then we assume that the entry is a space character, For simplicity, we assume that the entries in the list are in row-major order. This means that each row is listed from left to right, one row after the other. Thus the 3 by 3 grid below: 1x1 lol | Ixlol 11x1 would be represented by the list: [((0,0),'*'),((0,2), '0'), ((1,1). 'x'),((1,2), '0'), ((2, 2), 'x')] The horizontal and vertical lines are there to make the grid more readable and are not in the list. You will notice that all the elements in row 0 are listed from left to right, then the elements of row 1, etc. (a) Please write a function lessThan (1,3) (m,n) that determines if index (1,3) comes strictly before index (m, n) in row-major order as described above. Thus lessThan (1,4) (2,2) should return True. It should have type less Than :: (Ord a, Ord al) => (a, al) -> (a, a1) -> Bool Note that works as expected on pairs of integers. (b) Please write a function valid numrows numcols (rc) that determines if a row-column pair (r, c) is legal for a table with the numrows rows and numcols columns. Note that legal row numbers go from 0 to numrows -1, and similarly for columns. It should have type: valid :: (Num a, Num al, Ord a, Ord a1) => a -> al -> (a, al) -> Bool

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

Making Databases Work The Pragmatic Wisdom Of Michael Stonebraker

Authors: Michael L. Brodie

1st Edition

1947487167, 978-1947487161

More Books

Students also viewed these Databases questions