Haskell: How to use attoparsec in order to read a nested list from a ByteString

后端 未结 1 546
Happy的楠姐
Happy的楠姐 2021-01-15 13:04

I have a text file (~ 300 MB large) with a nested list, similar to this one:

[[4, 9, 11, 28, 30, 45, 55, 58, 61, 62, 63, 69, 74, 76, 77, 82, 87, 92, 93, 94,          


        
1条回答
  •  余生分开走
    2021-01-15 13:11

    The data seems to be in JSON format, so you can use Data.Aeson decode function which works on ByteString

    import qualified Data.ByteString.Lazy as BL
    import Data.Aeson
    import Data.Maybe
    
    main = do fContents <- BL.readFile filePath 
              let numList = decode fContents :: Maybe [[Int]]
              putStrLn (show $ fromJust numList)
    

    0 讨论(0)
提交回复
热议问题