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: addMat :: Num a => Matrix a -> Matrix a ->

Matrices in Haskell: 
type Matrix a = [[a]]
i need to create a function: addMat :: Num a => Matrix a -> Matrix a -> Maybe (Matrix a) 

which takes two matrices and adds them together. Matrices may only be added together if they have the same number of rows and columns. If they do not, return Nothing. If they do, the values in the result matrix are the addition of the two values at the same positions in the two argument matrices. For example:

 > addMat eg1 eg1 Just [[2,6],[0,10],[-6,8],[4,4]] > addMat eg1 eg2 Nothing > addMat eg3 eg3 Nothing

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

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

9th Edition

0135188148, 978-0135188149, 9781642087611

More Books

Students also viewed these Databases questions

Question

12-5 How will MIS help my career?

Answered: 1 week ago