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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!