Haskell 缩进块 "last statement in a do-block must be an expression"

Haskell indentation block "last statement in a do-block must be an expression"

我对 haskell 缩进非常困惑,尤其是 do 块与 letwhere

我在 action <- 行收到以下错误 "last statement in a do-block must be an expression" 我应该如何解决这个问题?

我有如下定义

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

loop 的正文需要比其名称缩进更多。例如:

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
      ...