代码之家  ›  专栏  ›  技术社区  ›  bbarker

为什么putStrLn似乎可以改变IO monad中的预期类型?

  •  1
  • bbarker  · 技术社区  · 7 年前

    我有以下基于csv管道的简单函数,它调用一个自定义 catMaybes 实施 Vector 美国。

    retrieveSmaXtec :: IO (Vector SxRecord)
    retrieveSmaXtec = do
      rows <- sourceFile "unordered.csv"
        .| intoCSV defCSVSettings
        .| sinkVector
        & runConduitRes
      putStrLn $ show $ size rows  -- DEBUG
      putStrLn $ show $ size $ (fmap fromRow rows) -- DEBUG
      rows & fmap fromRow & catMaybes & return
    

    putStrLn fromRow 普斯特林 打电话,我得到错误:

    src/FDS/Data/SmaXtec.hs:64:25: error:                                                                                                       
        * Couldn't match type `Map k0 (Maybe SxRecord)'                                                                                         
                         with `Vector (Maybe SxRecord)'                                                                                         
          Expected type: Map k0 (Maybe SxRecord) -> Vector SxRecord                                                                             
            Actual type: Vector (Maybe SxRecord) -> Vector SxRecord                                                                             
        * In the second argument of `(&)', namely `catMaybes'                                                                                   
          In the first argument of `(&)', namely                                                                                                
            `rows & fmap fromRow & catMaybes'                                                                                                   
          In a stmt of a 'do' block: rows & fmap fromRow & catMaybes & return                                                                   
        * Relevant bindings include                                                                                                             
            rows :: Map k0 (MapRow Text)                                                                                                        
              (bound at src/FDS/Data/SmaXtec.hs:58:3)                                                                                           
       |                                                                                                                                        
    64 |   rows & fmap fromRow & catMaybes & return                                                                                             
       |                         ^^^^^^^^^           
    

    更新: 正如评论中暗示的那样, size 不是我要找的功能。我需要 Data.Vector.length

    0 回复  |  直到 7 年前
    推荐文章