Question: Haskell Question I have the following code: -- Represent a 2x2 matrix, e.g., -- ( 3 1 ) -- ( 4 0 ) -- becomes
Haskell Question
I have the following code:
-- Represent a 2x2 matrix, e.g.,
-- ( 3 1 )
-- ( 4 0 )
-- becomes
-- MkMat 3 1 4 0
data Mat a = MkMat a a a a
deriving (Eq, Show)
How can I write the following functions for addition, negation and multiplication?
instance Num a => Num (Mat a) where
(+) :: Mat a -> Mat a -> Mat a
negate :: Mat a -> Mat a
(*) :: Mat a -> Mat a -> Mat a
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
