gpt4 book ai didi

haskell - 多行 if 语句 Haskell

转载 作者:行者123 更新时间:2023-12-02 02:01:39 25 4
gpt4 key购买 nike

我正在用 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 语句中使用多行。是否可以使用某种限制器,以便我可以使用 let 之类的东西如果?

最佳答案

您需要重复 do每个 then 上的关键字/else分支。

whatever = do
step1
step2
if foo
then do
thing1
thing2
thing3
else do
thing5
thing6
thing7
thing8

关于haskell - 多行 if 语句 Haskell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27487505/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com