Question: Matrcies in Haskell: type Matrix a = [[a]] i need to create a function: identity :: Int -> Maybe (Matrix Int) that returns the Identity
Matrcies in Haskell:
type Matrix a = [[a]]
i need to create a function:
identity :: Int -> Maybe (Matrix Int)
that returns the Identity matrix for the given size. An Identity matrix is a square matrix which has zero for all values, except the values on the top-left to bottom-right diagonal which are all one. If the size is less than 1, then the identity matrix isn't defined and Nothing should be returned. For example:
> identity 2 Just [[1,0],[0,1]] > identity 5 Just [[1,0,0,0,0],[0,1,0,0,0],[0,0,1,0,0],[0,0,0,1,0],[0,0,0,0,1]] > identity 0 Nothing > identity (-1) Nothing
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
