我想通過編程一個簡單的數學學習程序來同時學習數學和Haskell。爲什麼程序流量控制是隨機執行的
它首先:
- 生成隨機數。
- 過濾這些數字可以創建一個簡單的問題。
- 顯示的問題,然後把我的答案
- 最後,它交給我的兩個答案與正確答案給另一個函數給我的反饋(「恭喜」 - 或 - 「對不起,正確的答案是空白。)
出於某種原因,祝賀函數結束後,它似乎隨機選擇的地方去下一個,或者:
- 它返回到主(這是我期望它做)
- 或者隨機循環,它會立即進入數學測試功能。發生這種情況時,步驟2從上面不會發生,我開始在問題中得到小數。然後它可能會重複此步驟或返回主要。
當試圖調試我只是不停的按RETURN問題,它會出現在不同的時間。我還添加了一些調試「打印」語句。
這是程序的3個功能。請注意,主要調用funPercentOfNumberToAnother:
funPercentOfNumberToAnother :: IO()
funPercentOfNumberToAnother = do
(percentDec, percentStr) <- getPercent
ofNum <- getDecimal (200 :: Decimal)
let isNum = percentDec * ofNum
if uglyAnswers ([ofNum, isNum], [percentDec])
then do
putStrLn ("ofNum: " ++ show ofNum)
putStrLn ("isNum: " ++ show isNum)
putStrLn "___________________________"
funPercentOfNumberToAnother
else do
putStrLn ("ofNum: " ++ show ofNum)
putStrLn ("isNum: " ++ show isNum)
putStrLn "Percents"
-- putStrLn "\n\n"
putStrLn (show isNum ++ " is what percent of " ++ show ofNum ++ "?\n")
putStr "> "
ans <- getLine
submitStringAnswer (ans, percentStr ++ "%")
submitStringAnswer :: (String, String) -> IO()
submitStringAnswer (myAns, correctAns) = do
if myAns == correctAns
then putStrLn "Congratz!"
else do
putStrLn ("Sorry the correct answer is: " ++ show correctAns)
pause
pause :: IO()
pause = do
x <- getLine
putStrLn ""
這是我的調試輸出。請注意,只有當暫停結束後,它纔會立即返回到主體。
__ __ _ _ _ _
| \/ | __ _| |_| |__ ___ _ __ ___ __ _| |_(_) ___ ___
| |\/| |/ _` | __| '_ \/_ \ '_ ` _ \/_` | __| |/ __/ __|
| | | | (_| | |_| | | | __/ | | | | | (_| | |_| | (__\__
|_| |_|\__,_|\__|_| |_|\___|_| |_| |_|\__,_|\__|_|\___|___/
1.) Learn Math
2.) Math Lookup
3.) Quit Excolo
1
ofNum: 35
isNum: 15.75
___________________________
ofNum: 120
isNum: 102
Percents
102 is what percent of 120?
>
Sorry the correct answer is: "85%"
15.75 is what percent of 35?
>
Sorry the correct answer is: "45%"
__ __ _ _ _ _
| \/ | __ _| |_| |__ ___ _ __ ___ __ _| |_(_) ___ ___
| |\/| |/ _` | __| '_ \/_ \ '_ ` _ \/_` | __| |/ __/ __|
| | | | (_| | |_| | | | __/ | | | | | (_| | |_| | (__\__
|_| |_|\__,_|\__|_| |_|\___|_| |_| |_|\__,_|\__|_|\___|___/
1.) Learn Math
2.) Math Lookup
3.) Quit Excolo
1
ofNum: 80
isNum: 44
Percents
44 is what percent of 80?
>
Sorry the correct answer is: "55%"
__ __ _ _ _ _
| \/ | __ _| |_| |__ ___ _ __ ___ __ _| |_(_) ___ ___
| |\/| |/ _` | __| '_ \/_ \ '_ ` _ \/_` | __| |/ __/ __|
| | | | (_| | |_| | | | __/ | | | | | (_| | |_| | (__\__
|_| |_|\__,_|\__|_| |_|\___|_| |_| |_|\__,_|\__|_|\___|___/
1.) Learn Math
2.) Math Lookup
3.) Quit Excolo
1
ofNum: 15
isNum: 2.25
___________________________
ofNum: 60
isNum: 0.6
___________________________
ofNum: 40
isNum: 30
Percents
30 is what percent of 40?
>
Sorry the correct answer is: "75%"
0.6 is what percent of 60?
>
Sorry the correct answer is: "1%"
2.25 is what percent of 15?
>
Sorry the correct answer is: "15%"
如果有幫助,這是遠程相關的是我迄今爲止發現的唯一的事情就是:Second of several forked processes does not run in Haskell 。
最後,如果這有助於制定您的答案,我就是Monad的入門級別。
我會很感激任何人可以提供什麼幫助,爲什麼它不是直接返回到主要暫停結束,爲什麼它會跳過分數過濾器。
謝謝^^