【发布时间】:2014-12-15 15:31:47
【问题描述】:
我正在用 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
它需要一个棋盘,如果玩家可以根据掷骰子移动,则返回新棋盘,否则返回旧棋盘。
但是,haskell 不允许我在 if 语句中使用多行。是否可以使用某种限制器,以便我可以在 if 中使用 let 之类的东西?
【问题讨论】:
-
样式:
"Possible columns to move: " ++ (show $ moves)可以简化为"Possible columns to move: " ++ show moves。当右边有一个变量时不要使用$:它是多余的。 -
@chi:谢谢!在我发布之前应该使用 hlint ;)
标签: haskell if-statement