title: Matrix constructor and method in Haskell
body: <p>So here is a nested list [[1, 2], [3, 4]]</p>
  
  <p>I want to wrap it in a type called Matrix, and make it an instance of the classes Eq, Num, and Show</p>
  
  <p>I have already created (add, sub, mul) operations for nested lists (matrices).  How do I overload (+ - *) operators so that + maps to add, - maps to sub, and * maps to mul?  So I can do this</p>
  
  <pre><code>&gt; ma = Matrix [[1, 2], [3, 4]]
  &gt; mb = Matrix [[5, 6], [7, 8]]
  &gt; ma + mb
  &gt; ma - mb
  &gt; ma * mb
  </code></pre>
  
  <p>Thanks</p>
  
  <p>EDIT</p>
  
  <p>this is my attempt so far</p>
  
  <pre>
  > add = zipWith (zipWith (+))
  > sub = zipWith (zipWith (-))
  > data Matrix a = Matrix [[a]] deriving (Eq, Show)
  > instance Num (Matrix a)
  >   where
  >   (+) x y = Matrix $ add x y
  >   (-) x y = Matrix $ sub x y
  </pre>
  
  <p>This is what I get from ghci</p>
  
  <pre>
   Couldn't match expected type `[[c0]]' with actual type `Matrix a'
      In the first argument of `sub', namely `x'
      In the second argument of `($)', namely `sub x y'
      In the expression: Matrix $ sub x y
  </pre>
  
  <p>EDIT #2
  The last thing I need to figure out right now is</p>
  
  <p>how to I print </p>
  
  <pre>
  1 2
  3 4
  </pre>
  
  <p>Instead of Matrix [[1,2],[3,4]]</p>