作者:铜钱 | 来源:互联网 | 2023-09-17 19:10
我正在尝试以下功能:
repcountIORIban :: IORef -> Int -> Int -> Int -> Int -> Lock -> IORef -> Lock -> Int -> Int -> IO ()
repcountIORIban count number lower modulus amountthreads lock done lock2 difference rest = do
if rest > number
then let extra = 1
else let extra = 0
if number + 1 then
forkIO $ realcountIORIban(count lower (lower + difference + extra - 1) modulus lock done lock2)
repcountIORIban (count (number + 1) (lower + difference + extra) modulus amountthreads lock done lock2 difference rest)
else
forkIO $ realcountIORIban(count lower (lower + difference + extra - 1) modulus lock done lock2)
但是我无法运行该功能所在的程序。它给了我错误:
error: parse error on input `else'
|
113 | else let extra = 0
| ^^^^
我的程序经常出现此错误,但是我不知道自己在做什么错。
这是不正确的,您不能在let
/ then
之后else
并期望这些let
定义绑定,这些绑定在下面可见。
do if rest > number
then let extra = 1 -- wrong,needs a "do",or should be "let .. in .."
else let extra = 0
... -- In any case,extra is not visible here
试试看
do let extra = if rest > number
then 1
else 0
...
此外,如果之后需要执行两个或多个操作,则需要then do
。
if number + 1 then do
something
somethingElse
else -- use do here if you have two or more actions
...