我想製作一個簡單的程序,在其中我可以添加矩形列表(id,width,height)並顯示帶specyfic id(id,width,height)的矩形 - 我想我有在下面的代碼中有多個錯誤 - 你知道什麼可能是錯的嗎?我將命令「menuRectangles」(現在這不工作)運行以下命令:將矩形添加到列表中並顯示矩形
import IO
import Char
menuRectangles = do
putStrLn "Please choose option:"
putStrLn "1 - Add rectangle"
putStrLn "2 - Show rectangle"
putStrLn "3 - Quit"
putStr "Number: ";
n <- getLine
case n of
"1" -> do addRectangle; menuRectangles;
"2" -> do showRectangle; menuRectangles;
"3" -> menuRectangles;
otherwise -> putStrLn "The End";
addRectangle = do
putStrLn "Id: "
id <- getLine
putStrLn "Width: "
width <- getLine
putStrLn "Height: "
height <- getLine
addingRectangle (Rectangle id width height);
showRectangle = do
putStrLn "Choose id rectangle: "
id <- getLine
showingRectangle r[id];
data RectangleType = Rectangle Int Int Int deriving(Show)
addingRectangle r [] = [r]
addingRectangle r rx = r:rx
showingRectangle (Rectangle id width height) = "id: " ++ show id ++ "width: " ++ show width ++ "height: " ++ height ++ "\n";
您將需要詢問更具體的問題。究竟出了什麼問題,你想做什麼。簡單地列出你的代碼是不可接受的。 – 2011-04-17 17:55:20
我只想指出,您必須使用非常舊的教科書或學習資料,因爲像「import char」這樣的舊式不合格進口不再使用。 – 2011-04-17 18:18:07
我有錯誤:不在範圍內:'r' – mrquestion 2011-04-17 18:49:22