即使编译器建议使用Text也会导致错误

时间:2016-10-24 20:46:28

标签: haskell yesod

我可能误读了编译器的建议,但当我尝试传递Text值时,它会抱怨。

调整websocket example我尝试传递编码对象。我已将我的示例简化为以下内容,我尝试传递"someText" :: Text

race_
    (forever $ atomically (readTChan readChan) >>= sendTextData)
    (sourceWS $$ mapM_C (\msg -> atomically $ writeTChan writeChan ("someText" :: Text)))

但是,我收到此错误消息:

No instance for (websockets-0.9.7.0:Network.WebSockets.Types.WebSocketsData
                   a0)
  arising from a use of ‘sourceWS’
The type variable ‘a0’ is ambiguous
Note: there are several potential instances:
  instance websockets-0.9.7.0:Network.WebSockets.Types.WebSocketsData
             Text
    -- Defined in ‘websockets-0.9.7.0:Network.WebSockets.Types’
  instance websockets-0.9.7.0:Network.WebSockets.Types.WebSocketsData
             Data.Text.Internal.Lazy.Text
    -- Defined in ‘websockets-0.9.7.0:Network.WebSockets.Types’
  instance websockets-0.9.7.0:Network.WebSockets.Types.WebSocketsData
             ByteString
    -- Defined in ‘websockets-0.9.7.0:Network.WebSockets.Types’
  ...plus one other
In the first argument of ‘($$)’, namely ‘sourceWS’
In the second argument of ‘race_’, namely
  ‘(sourceWS
    $$
      mapM_C
        (\ msg -> atomically $ writeTChan writeChan ("someText" :: Text)))’
In a stmt of a 'do' block:
  race_
    (forever $ atomically (readTChan readChan) >>= sendTextData)
    (sourceWS
     $$
       mapM_C
         (\ msg -> atomically $ writeTChan writeChan ("someText" :: Text)))

1 个答案:

答案 0 :(得分:2)

sourceWS :: (MonadIO m, WebSocketsData a) => Producer (WebSocketsT m) a 

我假设$$mapM_C以某种方式将输出a附加到lambda msg的参数\msg -> ...。但是,您永远不会使用msg,因此编译器无法确定它应为a选择的类型sourceWS,因为它说:

No instance for (websockets-0.9.7.0:Network.WebSockets.Types.WebSocketsData
               a0)
  arising from a use of ‘sourceWS’
The type variable ‘a0’ is ambiguous