我对haskell缩进感到非常困惑,特别是do
阻止了let
和where
我在行action <-
&#34上遇到以下错误; do-block中的最后一个语句必须是表达式&#34;我该如何解决这个问题?
我有以下定义
type NeovimRead = Neovim r st Text
type NeovimWrite = Text -> Neovim r st ()
consumeLoop :: Server -> NeovimRead -> NeovimWrite -> Neovim r st ()
consumeLoop server read write = do
status <- liftIO $ takeMVar (status server)
if status == Running
then loop
else liftIO $ putMVar (status server) status
where loop = do
action <- liftIO $ readaction server
case action of
ReadBuffer -> do
text <- read
liftIO $ putMVar (buffer server) text
WriteBuffer -> do
text <- liftIO $ takeMVar (buffer server)
write text
liftIO $ putMVar (status server) Running
consumeLoop server read write
答案 0 :(得分:3)
loop
的主体需要缩进而不是名称。 e.g:
consumeLoop :: Server -> NeovimRead -> NeovimWrite -> Neovim r st ()
consumeLoop server read write = do
status <- liftIO $ takeMVar (status server)
if status == Running
then loop
else liftIO $ putMVar (status server) status
where
loop = do
action <- liftIO $ readaction server
...