﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>IT博客-gyn-随笔分类-Haskell</title><link>http://www.cnitblog.com/gyn/category/7724.html</link><description>Win32下的Perl，无用的select，停滞的Tk，结束吧....</description><language>zh-cn</language><lastBuildDate>Wed, 28 Sep 2011 07:08:33 GMT</lastBuildDate><pubDate>Wed, 28 Sep 2011 07:08:33 GMT</pubDate><ttl>60</ttl><item><title>Yet Another Haskell Tutorial中Exercise 3.10的答案</title><link>http://www.cnitblog.com/gyn/archive/2008/09/27/49590.html</link><dc:creator>gyn_tadao</dc:creator><author>gyn_tadao</author><pubDate>Sat, 27 Sep 2008 11:28:00 GMT</pubDate><guid>http://www.cnitblog.com/gyn/archive/2008/09/27/49590.html</guid><wfw:comment>http://www.cnitblog.com/gyn/comments/49590.html</wfw:comment><comments>http://www.cnitblog.com/gyn/archive/2008/09/27/49590.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.cnitblog.com/gyn/comments/commentRss/49590.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/gyn/services/trackbacks/49590.html</trackback:ping><description><![CDATA[
		<div class="Section0" style="">
				<p class="p0" style="margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
						<span style="font-size: 10.5pt; font-family: '黑体';">因为是刚开始看</span>
						<span style="font-size: 10.5pt; font-family: 'Courier New';"> haskell </span>
						<span style="font-size: 10.5pt; font-family: '黑体';">所以很多概念不是很清楚，比如何时用</span>
						<span style="font-size: 10.5pt; font-family: 'Courier New';"> do </span>
						<span style="font-size: 10.5pt; font-family: '黑体';">、“</span>
						<span style="font-size: 10.5pt; font-family: 'Courier New';"> &lt;- </span>
						<span style="font-size: 10.5pt; font-family: '黑体';">”和</span>
						<span style="font-size: 10.5pt; font-family: 'Courier New';"> let </span>
						<span style="font-size: 10.5pt; font-family: '黑体';">。</span>
						<span style="font-size: 10.5pt; font-family: 'Courier New';"> Exerceise3.10 </span>
						<span style="font-size: 10.5pt; font-family: '黑体';">算是做出来，但是肯定不是一个好办法。希望给我改改吧，顺便解答一下我的疑问。不得不说的是编译信息相当地没有用啊，这真是太遗憾了。</span>
						<span style="font-size: 10.5pt; font-family: 'Courier New';">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="p0" style="padding: 0pt; background: rgb(217, 217, 217) none repeat scroll 0% 0%; margin-bottom: 0pt; margin-top: 0pt; text-align: justify; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
						<span style="font-size: 10.5pt; font-family: 'Courier New';">module Main</span>
						<span style="font-size: 10.5pt; font-family: 'Courier New';">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="p0" style="padding: 0pt; background: rgb(217, 217, 217) none repeat scroll 0% 0%; margin-bottom: 0pt; margin-top: 0pt; text-align: justify; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
						<span style="font-size: 10.5pt; font-family: 'Courier New';">   where</span>
						<span style="font-size: 10.5pt; font-family: 'Courier New';">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="p0" style="padding: 0pt; background: rgb(217, 217, 217) none repeat scroll 0% 0%; margin-bottom: 0pt; margin-top: 0pt; text-align: justify; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
						<span style="font-size: 10.5pt; font-family: 'Courier New';">   </span>
						<span style="font-size: 10.5pt; font-family: 'Courier New';">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="p0" style="padding: 0pt; background: rgb(217, 217, 217) none repeat scroll 0% 0%; margin-bottom: 0pt; margin-top: 0pt; text-align: justify; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
						<span style="font-size: 10.5pt; font-family: 'Courier New';">import IO</span>
						<span style="font-size: 10.5pt; font-family: 'Courier New';">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="p0" style="padding: 0pt; background: rgb(217, 217, 217) none repeat scroll 0% 0%; margin-bottom: 0pt; margin-top: 0pt; text-align: justify; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
						<span style="font-size: 10.5pt; font-family: 'Courier New';"> </span>
						<span style="font-size: 10.5pt; font-family: 'Courier New';">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="p0" style="padding: 0pt; background: rgb(217, 217, 217) none repeat scroll 0% 0%; margin-bottom: 0pt; margin-top: 0pt; text-align: justify; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
						<span style="font-size: 10.5pt; font-family: 'Courier New';">main = do</span>
						<span style="font-size: 10.5pt; font-family: 'Courier New';">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="p0" style="padding: 0pt; background: rgb(217, 217, 217) none repeat scroll 0% 0%; margin-bottom: 0pt; margin-top: 0pt; text-align: justify; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
						<span style="font-size: 10.5pt; font-family: 'Courier New';">   list &lt;- askForNumber</span>
						<span style="font-size: 10.5pt; font-family: 'Courier New';">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="p0" style="padding: 0pt; background: rgb(217, 217, 217) none repeat scroll 0% 0%; margin-bottom: 0pt; margin-top: 0pt; text-align: justify; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
						<span style="font-size: 10.5pt; font-family: 'Courier New';">   let </span>
						<span style="font-size: 10.5pt; font-family: 'Courier New';">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="p0" style="padding: 0pt; background: rgb(217, 217, 217) none repeat scroll 0% 0%; margin-bottom: 0pt; margin-top: 0pt; text-align: justify; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
						<span style="font-size: 10.5pt; font-family: 'Courier New';">      sAdd = show (foldl (+) 0 list)</span>
						<span style="font-size: 10.5pt; font-family: 'Courier New';">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="p0" style="padding: 0pt; background: rgb(217, 217, 217) none repeat scroll 0% 0%; margin-bottom: 0pt; margin-top: 0pt; text-align: justify; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
						<span style="font-size: 10.5pt; font-family: 'Courier New';">      sMul = show (foldl (*) 1 list)</span>
						<span style="font-size: 10.5pt; font-family: 'Courier New';">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="p0" style="padding: 0pt; background: rgb(217, 217, 217) none repeat scroll 0% 0%; margin-bottom: 0pt; margin-top: 0pt; text-align: justify; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
						<span style="font-size: 10.5pt; font-family: 'Courier New';">   putStrLn ("The sum is " ++ sAdd)</span>
						<span style="font-size: 10.5pt; font-family: 'Courier New';">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="p0" style="padding: 0pt; background: rgb(217, 217, 217) none repeat scroll 0% 0%; margin-bottom: 0pt; margin-top: 0pt; text-align: justify; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
						<span style="font-size: 10.5pt; font-family: 'Courier New';">   putStrLn ("The production is " ++ sMul)</span>
						<span style="font-size: 10.5pt; font-family: 'Courier New';">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="p0" style="padding: 0pt; background: rgb(217, 217, 217) none repeat scroll 0% 0%; margin-bottom: 0pt; margin-top: 0pt; text-align: justify; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
						<span style="font-size: 10.5pt; font-family: 'Courier New';">   putFactorial list</span>
						<span style="font-size: 10.5pt; font-family: 'Courier New';">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="p0" style="padding: 0pt; background: rgb(217, 217, 217) none repeat scroll 0% 0%; margin-bottom: 0pt; margin-top: 0pt; text-align: justify; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
						<span style="font-size: 10.5pt; font-family: 'Courier New';">          </span>
						<span style="font-size: 10.5pt; font-family: 'Courier New';">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="p0" style="padding: 0pt; background: rgb(217, 217, 217) none repeat scroll 0% 0%; margin-bottom: 0pt; margin-top: 0pt; text-align: justify; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
						<span style="font-size: 10.5pt; font-family: 'Courier New';">askForNumber = do</span>
						<span style="font-size: 10.5pt; font-family: 'Courier New';">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="p0" style="padding: 0pt; background: rgb(217, 217, 217) none repeat scroll 0% 0%; margin-bottom: 0pt; margin-top: 0pt; text-align: justify; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
						<span style="font-size: 10.5pt; font-family: 'Courier New';">   putStrLn "Give me a number (or 0 to top):"</span>
						<span style="font-size: 10.5pt; font-family: 'Courier New';">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="p0" style="padding: 0pt; background: rgb(217, 217, 217) none repeat scroll 0% 0%; margin-bottom: 0pt; margin-top: 0pt; text-align: justify; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
						<span style="font-size: 10.5pt; font-family: 'Courier New';">   sNum &lt;- getLine</span>
						<span style="font-size: 10.5pt; font-family: 'Courier New';">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="p0" style="padding: 0pt; background: rgb(217, 217, 217) none repeat scroll 0% 0%; margin-bottom: 0pt; margin-top: 0pt; text-align: justify; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
						<span style="font-size: 10.5pt; font-family: 'Courier New';">   let num = read sNum</span>
						<span style="font-size: 10.5pt; font-family: 'Courier New';">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="p0" style="padding: 0pt; background: rgb(217, 217, 217) none repeat scroll 0% 0%; margin-bottom: 0pt; margin-top: 0pt; text-align: justify; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
						<span style="font-size: 10.5pt; font-family: 'Courier New';">   if num == 0</span>
						<span style="font-size: 10.5pt; font-family: 'Courier New';">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="p0" style="padding: 0pt; background: rgb(217, 217, 217) none repeat scroll 0% 0%; margin-bottom: 0pt; margin-top: 0pt; text-align: justify; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
						<span style="font-size: 10.5pt; font-family: 'Courier New';">      then return []</span>
						<span style="font-size: 10.5pt; font-family: 'Courier New';">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="p0" style="padding: 0pt; background: rgb(217, 217, 217) none repeat scroll 0% 0%; margin-bottom: 0pt; margin-top: 0pt; text-align: justify; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
						<span style="font-size: 10.5pt; font-family: 'Courier New';">      else do</span>
						<span style="font-size: 10.5pt; font-family: 'Courier New';">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="p0" style="padding: 0pt; background: rgb(217, 217, 217) none repeat scroll 0% 0%; margin-bottom: 0pt; margin-top: 0pt; text-align: justify; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
						<span style="font-size: 10.5pt; font-family: 'Courier New';">          rest &lt;- askForNumber</span>
						<span style="font-size: 10.5pt; font-family: 'Courier New';">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="p0" style="padding: 0pt; background: rgb(217, 217, 217) none repeat scroll 0% 0%; margin-bottom: 0pt; margin-top: 0pt; text-align: justify; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
						<span style="font-size: 10.5pt; font-family: 'Courier New';">          return (num : rest)</span>
						<span style="font-size: 10.5pt; font-family: 'Courier New';">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="p0" style="padding: 0pt; background: rgb(217, 217, 217) none repeat scroll 0% 0%; margin-bottom: 0pt; margin-top: 0pt; text-align: justify; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
						<span style="font-size: 10.5pt; font-family: 'Courier New';">          </span>
						<span style="font-size: 10.5pt; font-family: 'Courier New';">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="p0" style="padding: 0pt; background: rgb(217, 217, 217) none repeat scroll 0% 0%; margin-bottom: 0pt; margin-top: 0pt; text-align: justify; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
						<span style="font-size: 10.5pt; font-family: 'Courier New';">putFactorial [] = do</span>
						<span style="font-size: 10.5pt; font-family: 'Courier New';">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="p0" style="padding: 0pt; background: rgb(217, 217, 217) none repeat scroll 0% 0%; margin-bottom: 0pt; margin-top: 0pt; text-align: justify; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
						<span style="font-size: 10.5pt; font-family: 'Courier New';">   putStr ""</span>
						<span style="font-size: 10.5pt; font-family: 'Courier New';">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="p0" style="padding: 0pt; background: rgb(217, 217, 217) none repeat scroll 0% 0%; margin-bottom: 0pt; margin-top: 0pt; text-align: justify; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
						<span style="font-size: 10.5pt; font-family: 'Courier New';">   </span>
						<span style="font-size: 10.5pt; font-family: 'Courier New';">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="p0" style="padding: 0pt; background: rgb(217, 217, 217) none repeat scroll 0% 0%; margin-bottom: 0pt; margin-top: 0pt; text-align: justify; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
						<span style="font-size: 10.5pt; font-family: 'Courier New';">putFactorial (x : rest) = do</span>
						<span style="font-size: 10.5pt; font-family: 'Courier New';">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="p0" style="padding: 0pt; background: rgb(217, 217, 217) none repeat scroll 0% 0%; margin-bottom: 0pt; margin-top: 0pt; text-align: justify; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
						<span style="font-size: 10.5pt; font-family: 'Courier New';">   let fact = factorial x</span>
						<span style="font-size: 10.5pt; font-family: 'Courier New';">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="p0" style="padding: 0pt; background: rgb(217, 217, 217) none repeat scroll 0% 0%; margin-bottom: 0pt; margin-top: 0pt; text-align: justify; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
						<span style="font-size: 10.5pt; font-family: 'Courier New';">   putStrLn ((show x) ++ " factorial is " ++ (show fact))</span>
						<span style="font-size: 10.5pt; font-family: 'Courier New';">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="p0" style="padding: 0pt; background: rgb(217, 217, 217) none repeat scroll 0% 0%; margin-bottom: 0pt; margin-top: 0pt; text-align: justify; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
						<span style="font-size: 10.5pt; font-family: 'Courier New';">   putFactorial(rest)</span>
						<span style="font-size: 10.5pt; font-family: 'Courier New';">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="p0" style="padding: 0pt; background: rgb(217, 217, 217) none repeat scroll 0% 0%; margin-bottom: 0pt; margin-top: 0pt; text-align: justify; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
						<span style="font-size: 10.5pt; font-family: 'Courier New';"> </span>
						<span style="font-size: 10.5pt; font-family: 'Courier New';">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="p0" style="padding: 0pt; background: rgb(217, 217, 217) none repeat scroll 0% 0%; margin-bottom: 0pt; margin-top: 0pt; text-align: justify; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
						<span style="font-size: 10.5pt; font-family: 'Courier New';">factorial 1 = 1</span>
						<span style="font-size: 10.5pt; font-family: 'Courier New';">
								<o:p>
								</o:p>
						</span>
				</p>
				<p class="p0" style="border: medium none ; padding: 1pt 4pt; background: rgb(217, 217, 217) none repeat scroll 0% 0%; margin-bottom: 0pt; margin-top: 0pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
						<span style="font-size: 10.5pt; font-family: 'Courier New';">factorial x = x * factorial (x-1)</span>
						<span style="font-size: 10.5pt; font-family: 'Courier New';">
								<o:p>
								</o:p>
						</span>
				</p>
		</div>
<img src ="http://www.cnitblog.com/gyn/aggbug/49590.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/gyn/" target="_blank">gyn_tadao</a> 2008-09-27 19:28 <a href="http://www.cnitblog.com/gyn/archive/2008/09/27/49590.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>