开发者

Adding state to HXT parsing

开发者 https://www.devze.com 2023-02-06 17:10 出处:网络
I\'m trying to write an arrow that will generate numbered elements from an XML parse with HXT.It seems like it should be done with a state arrow, like the State monad, but all the examples I can find

I'm trying to write an arrow that will generate numbered elements from an XML parse with HXT. It seems like it should be done with a state arrow, like the State monad, but all the examples I can find in the HXT package and the methods to access the state (XmlState) use the IOStateArrow and I would much rather keep it pure to simplify the testing process, with the StateArrow. Do such variants exist? If not, how开发者_运维问答 would I add state to an HXT parse without having to resort to running the Arrow in IO?


You can use ArrowState instance of SLA for that. An example: let assume we need to concatenate all the second-level text elements.

Prelude Text.XML.HXT.Core> fst $ runSLA (xread >>> getChildren >>> getChildren >>> isText >>> getText >>> changeState (++)) "" "<xml><item>a</item><item>b</item></xml>" 
"ab"

Note, that you can't use IO inside the SLA since in doesn't have ArrowIO instance.

Hope, it is what you need.

0

精彩评论

暂无评论...
验证码 换一张
取 消