【问题标题】:Stream Vs Handle, respondHTTP throws error流与句柄,respondHTTP 抛出错误
【发布时间】:2015-07-05 10:42:25
【问题描述】:

Network.accept 在接受连接时返回给我一个句柄,我将其作为参数传递给respondHTTP(来自 Network.HTTP.Base) 它们的类型是,

accept :: Socket -> IO (Handle, HostName, PortNumber)
respondHTTP :: HStream ty => HandleStream ty -> Response ty -> IO ()

这一行——git-code

handleResponse = Kleisli (print ||| respondHTTP c)

,抛出错误,

simpleserver.hs:43:53:
    Couldn't match expected type ‘Network.TCP.HandleStream ty’
                with actual type ‘Handle’
    Relevant bindings include
      handleResponse :: Kleisli IO (Either b (Response ty)) ()
        (bound at simpleserver.hs:43:5)
    In the first argument of ‘respondHTTP’, namely ‘c’
    In the second argument of ‘(|||)’, namely ‘respondHTTP c’

如何将Handle(从Network.accept) 返回到Stream,然后再传递给respondHTTP

【问题讨论】:

    标签: sockets haskell stream


    【解决方案1】:

    来自Network.TCPHandleStream 和来自System.IOHandle 是两个不同的东西;没有超类-子类关系。它们不可互换。

    创建您的Socket,然后将其传递给socketConnection,而不是accept。这将返回您需要的 HandleStream

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-30
      • 2023-03-24
      • 2016-06-15
      • 1970-01-01
      • 1970-01-01
      • 2012-10-28
      相关资源
      最近更新 更多