Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Matrices in Haskell: type Matrix a = [[a]] i need to create two functions: 1) element' :: Matrix a -> Int -> Int -> a

Matrices in Haskell:

type Matrix a = [[a]]

i need to create two functions:

1) element' :: Matrix a -> Int -> Int -> a 

that returns the value in the matrix at the given row and column position. For this function you should assume that the row and column position will always be valid for the given matrix. For example:

 > element' eg1 0 1 3 > element' eg1 2 0 -3 > element' eg2 1 1 0

2) element :: Matrix a -> Int -> Int -> Maybe a

 

that returns the value in the matrix at the given row and column position, or Nothing if that is not a valid position for the given matrix.

 > element eg1 0 0 Just 1 > element eg1 0 1 Just 3 > element eg1 0 2 Nothing

some examples:

-- 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_2

Step: 3

blur-text-image_3

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

Beginning Apache Cassandra Development

Authors: Vivek Mishra

1st Edition

1484201426, 9781484201428

More Books

Students also viewed these Databases questions