<div class="gmail_quote"><br>
<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><code><span>type </span><span><font color="#2b91af">Matrix</font></span><span>=[[</span><span><font color="#2b91af">Double</font></span><span>]]</span><span>
</span></code></pre>
<p>Using this type you should define the following functions (definition of dim is given as an inspirational example).</p><pre><code><span>dim </span><span>::</span><span> </span><span><font color="#2b91af">Matrix</font></span><span> </span><span>-&gt;</span><span> </span><span>(</span><span><font color="#2b91af">Int</font></span><span>,</span><span><font color="#2b91af">Int</font></span><span>)</span><span> </span><span>--</span><span>returns matrix dimension </span><span>(</span><span>number of rows </span><span><font color="#00008b">and</font></span><span> columns</span><span>)</span><span>
dim m </span><span>=</span><span> </span><span><font color="#00008b">if</font></span><span> </span><span>(</span><span><font color="#00008b">not</font></span><span>.</span><span>isMatrix</span><span>)</span><span> m </span><span><font color="#00008b">then</font></span><span> error </span><span><font color="#800000">&quot;Not a matrix&quot;</font></span><span> </span><span><font color="#00008b">else</font></span><span> </span><span>(</span><span>length m</span><span>,</span><span> length </span><span>(</span><span>head m</span><span>))</span><span>

isMatrix </span><span>::</span><span> </span><span><font color="#2b91af">Matrix</font></span><span> </span><span>-&gt;</span><span> </span><span><font color="#2b91af">Bool</font></span><span> </span><span>--</span><span>checks whether all rows have the same length
isMatrix m </span><span>=</span><span>  </span><span><font color="#00008b">and</font></span><span> </span><span>[</span><span>length </span><span>(</span><span>head m</span><span>)</span><span> </span><span>==</span><span> length a </span><span>|</span><span> a </span><span>&lt;-</span><span> m</span><span>]</span><span>
</span></code></pre>
<p>I have done upto here and I am stuck on multSM.</p><pre><code><span>multSM </span><span>::</span><span> </span><span><font color="#2b91af">Double</font></span><span> </span><span>-&gt;</span><span> </span><span><font color="#2b91af">Matrix</font></span><span> </span><span>-&gt;</span><span> </span><span><font color="#2b91af">Matrix</font></span><span> </span><span>--</span><span>multiplies a scalar </span><span><font color="#00008b">and</font></span><span> a matrix
</span></code></pre>
<p>when I do:</p><pre><code><span>multSM  d m </span><span>=</span><span> </span><span>[[(</span><span>b</span><span>*</span><span>a</span><span>)|</span><span> b</span><span>&lt;-[</span><span>d</span><span>],</span><span> a</span><span>&lt;-(</span><span>head m</span><span>)]]</span><span> </span><span><font color="#00008b">or</font></span><span> </span><span>[</span><span>map </span><span>(*</span><span>d</span><span>)</span><span> </span><span>(</span><span>head m</span><span>)]</span><span>
</span></code></pre>
<p>...I get (using Hugs):</p><pre><code><span><font color="#2b91af">Main</font></span><span>&gt;</span><span> multSM </span><span><font color="#800000">3</font></span><span> </span><span>[[</span><span><font color="#800000">2</font></span><span>,</span><span><font color="#800000">3</font></span><span>,</span><span><font color="#800000">4</font></span><span>],[</span><span><font color="#800000">1</font></span><span>,</span><span><font color="#800000">3</font></span><span>,</span><span><font color="#800000">4</font></span><span>],[</span><span><font color="#800000">6</font></span><span>,</span><span><font color="#800000">3</font></span><span>,</span><span><font color="#800000">0</font></span><span>]]</span><span>
</span><span>[[</span><span><font color="#800000">6.0</font></span><span>,</span><span><font color="#800000">9.0</font></span><span>,</span><span><font color="#800000">12.0</font></span><span>]]</span><span>
</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></div><br>