Haskell缩进块" do-block中的最后一个语句必须是一个表达式"

时间:2016-04-02 19:52:06

标签: haskell indentation

我对haskell缩进感到非常困惑,特别是do阻止了letwhere

我在行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

1 个答案:

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