Haskell讀入一個字符串,把它轉換成數字

toint :: String->Int
toint' :: Char->Int
toint' s
	|s=='1' =1
	|s=='2' =2
	|s=='3' =3
	|s=='4' =4
	|s=='5' =5
	|s=='6' =6
	|s=='7' =7
	|s=='8' =8
	|s=='9' =9
	|s=='0' =0
	|otherwise = 0
toint (s:xs)=if null xs then toint' s else (toint xs)*10+(toint' s)
puts = do
	line <- getLine
	print (toint (reverse line));
	puts
Haskell好像對縮進要求很嚴

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章