Reputation: 496
I am very confused about haskell indentation especially do
block with let
and where
I got the following error on line action <-
"last statement in a do-block must be an expression" How should I fix this?
I have the following definition
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
Upvotes: 1
Views: 287
Reputation: 2643
The body of loop
needs to be indented more than its name. 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
...
Upvotes: 3