Question: 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
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
Get step-by-step solutions from verified subject matter experts
