Running Haskell HXT outside of IO?

前端 未结 2 1729
旧巷少年郎
旧巷少年郎 2020-12-30 21:44

All the examples I\'ve seen so far using the Haskell XML toolkit, HXT, uses runX to execute the parser. runX runs inside the IO monad. Is there a w

2条回答
  •  遥遥无期
    2020-12-30 22:22

    Travis Brown's answer was very helpful. I just want to add my own solution here, which I think is a bit more general (using the same functions, just ignoring the problem-specific issues).

    I was previously unpickling with:

    upIO      :: XmlPickler a => String -> IO [a]
    upIO str   = runX $ readString [] str >>> arrL (maybeToList . unpickleDoc xpickle)
    

    which I was able to change to this:

    upPure    :: XmlPickler a => String -> [a]
    upPure str = runLA (xreadDoc >>> arrL (maybeToList . unpickleDoc xpickle)) str
    

    I completely agree with him that doing this gives you less control over the configuration of the parser etc, which is unfortunate.

提交回复
热议问题