折叠箭头到列表
我在使用 HXT 时遇到了一些问题,尽管我怀疑这只是我的问题我缺少箭头。
我有一个像这样的 XML 结构
<str name="field1">value</str>
<lst name="field2"><str>value2</str><str>value3</str></lst>
和像这样的内部结构
data XmlData = XmlStr String | XmlList XmlData
有没有办法在箭头的步骤中收集元素?
getXmlData :: IOSArrow XmlTree (String, XmlData)
getXmlData = (getAttrl >>> getChildren >>> getText) &&&
((filterByType "str" >>> getText >>> arr (\x -> XmlStr x))
<+> (filterByType "lst" >>> getXmlData))
where filterByType t = isElem >>> hasName t >>> getChildren
对 getXmlData 的递归调用需要收集其答案并包装在 XmlList 构造函数中,但我不知道如何收集术语。目前,我正在通过对输出进行一些后处理(收集同名)来完成此任务,但我想要一个更好的解决方案。
I'm having some problems with HXT, though I suspect it's just something I'm missing about arrows.
I have an XML structure like
<str name="field1">value</str>
<lst name="field2"><str>value2</str><str>value3</str></lst>
And internal structure like
data XmlData = XmlStr String | XmlList XmlData
Is there a way to collect elements at a step in an arrow?
getXmlData :: IOSArrow XmlTree (String, XmlData)
getXmlData = (getAttrl >>> getChildren >>> getText) &&&
((filterByType "str" >>> getText >>> arr (\x -> XmlStr x))
<+> (filterByType "lst" >>> getXmlData))
where filterByType t = isElem >>> hasName t >>> getChildren
The recursive call to getXmlData needs to collect it's answer and wrap in an XmlList constructor, but I don't know how to collect terms. Currently I'm accomplishing this with some post processing on the output (collecting on the same name), but I would like a better solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般来说,您可以使用
Control.Arrow.ArrowList
来执行此操作。它的类型为(ArrowList a) =>; abc-> ab [c]
是一个(请参阅我的答案此处和此处查看具体示例。)
在这种特定情况下,您可以使用
>.
组合器将XmlList
构造函数作为其第二个参数,以更简洁地完成相同的操作。In general you can use
listA
fromControl.Arrow.ArrowList
to do this. It has type(ArrowList a) => a b c -> a b [c]
and is a(See my answers here and here for a concrete example.)
In this specific case you can use the
>.
combinator with theXmlList
constructor as its second argument to accomplish the same thing more concisely.