<div dir="ltr"><div class="gmail_default" style="font-family:gulimche,monospace">Do you intend to use list monad?</div><div class="gmail_default" style="font-family:gulimche,monospace">Since you bind the result of zip into powers,</div><div class="gmail_default" style="font-family:gulimche,monospace">powers has type (a,b).</div><div class="gmail_default"><div><font face="gulimche, monospace"><span style="white-space:pre-wrap">try changing that line:</span></font></div><div><span style="font-family:Osaka-等幅,Osaka-Mono,'\00ff2d\00ff33  \0030b4\0030b7\0030c3\0030af','MS Gothic',monospace">> let powers = zip coeffs (iterate (+1) 0)</span></div><div style="font-family:gulimche,monospace"><br></div><div style="font-family:gulimche,monospace">As Baojun says, you'd better to write pure function</div><div style="font-family:gulimche,monospace">and isolate I/O from it.</div><div style="font-family:gulimche,monospace"><br></div></div><div class="gmail_extra"><div class="gmail_quote">2016-04-22 12:33 GMT+09:00 Eunsu Kim <span dir="ltr"><<a href="mailto:wntuwntu@gmail.com" target="_blank">wntuwntu@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><div>Hi</div><div><br></div><div>i have a problem in my code!</div><div><br></div><div>here is my code:</div><div><br></div><div><div>-- Baic I/O and Loop (50 Points)</div><div><br></div><div>evalpoly = do <span style="white-space:pre-wrap">   </span>putStr "What is the degree of polynomial: "</div><div><span style="white-space:pre-wrap">            </span>degree <- getLine</div><div><span style="white-space:pre-wrap">             </span>coeffs <- (funcOfCoeff ((read degree::Int)+1) [])</div><div><span style="white-space:pre-wrap">             </span>putStr "What value do you want to evaluate at: "</div><div><span style="white-space:pre-wrap">               </span>value <- getLine<span style="white-space:pre-wrap">     </span></div><div><span style="white-space:pre-wrap">         </span>putStr "The value of the polynomial is: "</div><div><span style="white-space:pre-wrap">              </span>putStr (show (polyEvaluate (coeffs) (read value :: Float) ))</div><div><span style="white-space:pre-wrap">             </span>putStr "\n"</div><div><br></div><div>--function loop to get coefficient--</div><div><br></div><div>funcOfCoeff 0 coeffs = do <span style="white-space:pre-wrap">             </span>--to check the degree of 0</div><div><span style="white-space:pre-wrap">                       </span>return coeffs<span style="white-space:pre-wrap">   </span>--return list of coefficient</div><div><br></div><div>funcOfCoeff degree coeffs = do <span style="white-space:pre-wrap">     </span></div><div><span style="white-space:pre-wrap">                 </span>putStr ("What is the x^" ++ show(degree-1))<span style="white-space:pre-wrap">   </span></div><div><span style="white-space:pre-wrap">                 </span>putStr " coefficient: "</div><div><span style="white-space:pre-wrap">                        </span>coeff <- getLine</div><div><span style="white-space:pre-wrap">                      </span>loop <- funcOfCoeff (degree-1) ((read coeff :: Int) : coeffs)</div><div><span style="white-space:pre-wrap">                 </span>return loop</div><div><br></div><div><br></div><div><span style="white-space:pre-wrap">                    </span></div><div>polyEvaluate (coeffs) x = do</div><div><span style="white-space:pre-wrap"><div class="gmail_default" style="font-family:gulimche,monospace;display:inline">​​</div>                 </span>powers <- zip coeffs (iterate (+1) 0)</div><div><span style="white-space:pre-wrap">                 </span>result <- map (\(a,b)-> a+b) powers<span style="white-space:pre-wrap">       </span>—PROBLEM IS HERE!!!!</div><div><span style="white-space:pre-wrap">                   </span>return result</div><div><br></div><div><div>here is error message:</div><div><br></div><div><img height="152" width="375" src="cid:C6FEB6E1-8BDA-4837-AF14-F06EBE296C84"></div><div><br></div><div>in very bottom function (polyEvaluate), why is not working “result <- map (\(a,b) -> a+b) powers” ???</div><div><br></div><div>in Prelude, it is working</div><div><br></div><div><img height="46" width="285" src="cid:B2077ACB-2F62-4D6F-9ECA-92B1F7B0CB36"></div><div><br></div><div>Thanks!</div></div></div></div><br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div></div>