在这个脚本中,
permutations :: Integer -> Integer -> Integer
permutations x y
| x==x-(y-1) = x
| (x>0) && (y>0) = permutations (x-1) y * x
Run Code Online (Sandbox Code Playgroud)
我想知道为什么在函数排列中存在非穷举模式.
请帮我.
非常感谢你的进步!
我正在写一个程序来帮助我的弟弟学习加法.我没有编写IO程序的经验,而且我遇到了这个解析错误:
MyCode.hs:6:25:
Parse error in pattern: show
Possibly caused by a missing 'do'?
Run Code Online (Sandbox Code Playgroud)
代码:
mathExercise times (a,b) =
if times<=0
then return ()
else do let x = randInt a
let y = randInt b
putStr (show x ++ " + "++ show y++ " = ")
ans <- getInt
if (ans==x+y)
then do print True
mathExercise (times-1) (a,b)
else do print False
Run Code Online (Sandbox Code Playgroud)