使用Servant处理类型问题

时间:2017-09-09 22:56:14

标签: haskell

这是问题

server :: Req -> TVar Int ->  Server API
server r s = tran
    where
        tran ::  Maybe String -> BBuf -> ExceptT ServantErr IO Rq
        tran (Just m) b = do
          h <- liftIO $ atomReadT s
          let eb = EBuf b h
          let nb = Rq eb m []
          liftIO $ atomically (putTMVar (fst r) nb)
          liftIO $ atomRead (snd r)

我收到以下错误。

/apps/workspace/hade/src/Server/Service.hs:36:23: error:
    • Couldn't match expected type ‘Int’ with actual type ‘IO Int’
    • In the second argument of ‘EBuf’, namely ‘h’
      In the expression: EBuf b h
      In an equation for ‘eb’: eb = EBuf b h

任何帮助将不胜感激 - 卡尔

1 个答案:

答案 0 :(得分:1)

听起来你需要绑定b块中的do

server :: Req -> TVar Int ->  Server API
server r s = tran
    where
        tran ::  Maybe String -> BBuf -> ExceptT ServantErr IO Rq
        tran (Just m) b = do
          h <- liftIO $ atomReadT s
          b1 <- liftIO b
          let eb = EBuf b1 h
          let nb = Rq eb m []
          liftIO $ atomically (putTMVar (fst r) nb)
          liftIO $ atomRead (snd r)