Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Matrices in Haskell: type Matrix a = [[a]] i need to create a function: compress :: Num a => Matrix a -> Matrix a that

Matrices in Haskell: 
type Matrix a = [[a]]
i need to create a function: 
compress :: Num a => Matrix a -> Matrix a 

that takes an r-by-c Matrix and returns a new r-by-1 Matrix where the values in each row have been replaced by a length 1 list containing the total value from adding together all the values in that row. For example:

 > compress eg1 [[4],[5],[1],[4]] > compress eg5 [[10.599999999999998],[4.7]] > compress eg3 [[]]

Some examples are:

 -- 4 x 2 matrix eg1 :: Matrix Int eg1 = [ [1, 3], [0, 5], [-3, 4], [2, 2] ] -- 2 x 3 matrix eg2 :: Matrix Int eg2 = [ [3, 1, 4], [-1, 0, 5] ] -- 0 x 0 matrix, an empty matrix eg3 :: Matrix Int eg3 = [ [] ] -- 2x1 matrix eg4 :: Matrix Int eg4 = [ [2], [3] ] eg5 :: Matrix Double eg5 = [ [6.2, 4.3, 7.4, -7.3], [9.3, 1.2, 0.4, -6.2] ]

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

Big Data Systems A 360-degree Approach

Authors: Jawwad ShamsiMuhammad Khojaye

1st Edition

0429531575, 9780429531576

More Books

Students also viewed these Databases questions

Question

8. Managers are not trained to be innovation leaders.

Answered: 1 week ago