Pph*_*nix 7 haskell if-statement
我在Haskell中编写一个简单的程序,并具有以下功能:
tryMove board player die = do
let moves = getMoves board player die
putStrLn ("Possible columns to move: " ++ (show $ moves))
if not $ null moves then
let col = getOkInput $ moves
putStrLn " "
return $ step board (getMarker player) col firstDie
else
putStrLn ("No possible move using "++(show die)++"!")
return board
Run Code Online (Sandbox Code Playgroud)
它需要一块板,如果玩家可以根据掷骰子进行移动,则返回新板,否则返回旧板.
但是,haskell不允许我在if语句中使用多行.是否可以使用某种限制器,以便我可以使用letif中的东西?
Mat*_*hid 12
您需要do在每个then/ else分支上重复关键字.
whatever = do
step1
step2
if foo
then do
thing1
thing2
thing3
else do
thing5
thing6
thing7
thing8
Run Code Online (Sandbox Code Playgroud)