<p>Matrices</p>
<p>One of many ways to define matrices in Haskell is the list of matrix rows, where a row is a list of double precision oating point numbers:</p><pre class="prettyprint"><code><span class="pln">type </span><span class="typ"><font color="#2b91af">Matrix</font></span><span class="pun">=[[</span><span class="typ"><font color="#2b91af">Double</font></span><span class="pun">]]</span><span class="pln">
</span></code></pre>
<p>Using this type you should define the following functions (definition of dim is given as an inspirational example).</p><pre class="prettyprint"><code><span class="pln">dim </span><span class="pun">::</span><span class="pln"> </span><span class="typ"><font color="#2b91af">Matrix</font></span><span class="pln"> </span><span class="pun">-&gt;</span><span class="pln"> </span><span class="pun">(</span><span class="typ"><font color="#2b91af">Int</font></span><span class="pun">,</span><span class="typ"><font color="#2b91af">Int</font></span><span class="pun">)</span><span class="pln"> </span><span class="pun">--</span><span class="pln">returns matrix dimension </span><span class="pun">(</span><span class="pln">number of rows </span><span class="kwd"><font color="#00008b">and</font></span><span class="pln"> columns</span><span class="pun">)</span><span class="pln">
dim m </span><span class="pun">=</span><span class="pln"> </span><span class="kwd"><font color="#00008b">if</font></span><span class="pln"> </span><span class="pun">(</span><span class="kwd"><font color="#00008b">not</font></span><span class="pun">.</span><span class="pln">isMatrix</span><span class="pun">)</span><span class="pln"> m </span><span class="kwd"><font color="#00008b">then</font></span><span class="pln"> error </span><span class="str"><font color="#800000">&quot;Not a matrix&quot;</font></span><span class="pln"> </span><span class="kwd"><font color="#00008b">else</font></span><span class="pln"> </span><span class="pun">(</span><span class="pln">length m</span><span class="pun">,</span><span class="pln"> length </span><span class="pun">(</span><span class="pln">head m</span><span class="pun">))</span><span class="pln">

isMatrix </span><span class="pun">::</span><span class="pln"> </span><span class="typ"><font color="#2b91af">Matrix</font></span><span class="pln"> </span><span class="pun">-&gt;</span><span class="pln"> </span><span class="typ"><font color="#2b91af">Bool</font></span><span class="pln"> </span><span class="pun">--</span><span class="pln">checks whether all rows have the same length
isMatrix m </span><span class="pun">=</span><span class="pln">  </span><span class="kwd"><font color="#00008b">and</font></span><span class="pln"> </span><span class="pun">[</span><span class="pln">length </span><span class="pun">(</span><span class="pln">head m</span><span class="pun">)</span><span class="pln"> </span><span class="pun">==</span><span class="pln"> length a </span><span class="pun">|</span><span class="pln"> a </span><span class="pun">&lt;-</span><span class="pln"> m</span><span class="pun">]</span><span class="pln">
</span></code></pre>
<p>I have done upto here and I am stuck on multSM.</p><pre class="prettyprint"><code><span class="pln">multSM </span><span class="pun">::</span><span class="pln"> </span><span class="typ"><font color="#2b91af">Double</font></span><span class="pln"> </span><span class="pun">-&gt;</span><span class="pln"> </span><span class="typ"><font color="#2b91af">Matrix</font></span><span class="pln"> </span><span class="pun">-&gt;</span><span class="pln"> </span><span class="typ"><font color="#2b91af">Matrix</font></span><span class="pln"> </span><span class="pun">--</span><span class="pln">multiplies a scalar </span><span class="kwd"><font color="#00008b">and</font></span><span class="pln"> a matrix
</span></code></pre>
<p>when I do:</p><pre class="prettyprint"><code><span class="pln">multSM  d m </span><span class="pun">=</span><span class="pln"> </span><span class="pun">[[(</span><span class="pln">b</span><span class="pun">*</span><span class="pln">a</span><span class="pun">)|</span><span class="pln"> b</span><span class="pun">&lt;-[</span><span class="pln">d</span><span class="pun">],</span><span class="pln"> a</span><span class="pun">&lt;-(</span><span class="pln">head m</span><span class="pun">)]]</span><span class="pln"> </span><span class="kwd"><font color="#00008b">or</font></span><span class="pln"> </span><span class="pun">[</span><span class="pln">map </span><span class="pun">(*</span><span class="pln">d</span><span class="pun">)</span><span class="pln"> </span><span class="pun">(</span><span class="pln">head m</span><span class="pun">)]</span><span class="pln">
</span></code></pre>
<p>...I get (using Hugs):</p><pre class="prettyprint"><code><span class="typ"><font color="#2b91af">Main</font></span><span class="pun">&gt;</span><span class="pln"> multSM </span><span class="lit"><font color="#800000">3</font></span><span class="pln"> </span><span class="pun">[[</span><span class="lit"><font color="#800000">2</font></span><span class="pun">,</span><span class="lit"><font color="#800000">3</font></span><span class="pun">,</span><span class="lit"><font color="#800000">4</font></span><span class="pun">],[</span><span class="lit"><font color="#800000">1</font></span><span class="pun">,</span><span class="lit"><font color="#800000">3</font></span><span class="pun">,</span><span class="lit"><font color="#800000">4</font></span><span class="pun">],[</span><span class="lit"><font color="#800000">6</font></span><span class="pun">,</span><span class="lit"><font color="#800000">3</font></span><span class="pun">,</span><span class="lit"><font color="#800000">0</font></span><span class="pun">]]</span><span class="pln">
</span><span class="pun">[[</span><span class="lit"><font color="#800000">6.0</font></span><span class="pun">,</span><span class="lit"><font color="#800000">9.0</font></span><span class="pun">,</span><span class="lit"><font color="#800000">12.0</font></span><span class="pun">]]</span><span class="pln">
</span></code></pre>
<p>So I solve <code><font style="BACKGROUND-COLOR: #eeeeee" face="Consolas">3 [2,3,4]</font></code> but I do not know how to get the rest <code><font style="BACKGROUND-COLOR: #eeeeee" face="Consolas">3 [[1,3,4],[6,3,0]</font></code>.</p>

<p>Please help me on this problem.</p>