Hi,<br><br>Try to understand this:<br><br><div style="margin-left: 40px;"><span style="font-family: courier new,monospace;">type Matrix = [[Double]]</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">multSM :: Double -&gt; Matrix -&gt; Matrix</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">multSM d m = map (\ i -&gt; map (\ j -&gt; d*j ) i) m</span><br style="font-family: courier new,monospace;">
</div><br>Now try this for multSM (instead of the above definition)<br><br><div style="margin-left: 40px;"><span style="font-family: courier new,monospace;">multSM = map . map . (*)</span><br></div><br>Hope it helps,<br><br>
<br><div class="gmail_quote">On 2 February 2010 09:35, 조광래 <span dir="ltr">&lt;<a href="mailto:kwangraecho@gmail.com">kwangraecho@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="gmail_quote"><br>
<p>hi I have a question about haskell coding.</p>
<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: rgb(238, 238, 238);" face="Consolas">3 [2,3,4]</font></code> but I do not know how to get the rest <code><font style="background-color: rgb(238, 238, 238);" face="Consolas">3 [[1,3,4],[6,3,0]</font></code>.</p>


<p>Please help me on this problem.</p></div><br>
<br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>Ozgur Akgun<br>