I am trying to parse an XML file with https://hackage.haskell.org/package/hxt. In the code below, I need to parse the inner elements with an extra parameter obtained from an attribute in the outer tag. But i is not available in the second line (second arrow?). How can I pass i to the getTerminal?
getSentence = atTag "s" >>>
proc x -> do
i <- getAttrValue "id" -< x
ts <- listA (getTerminal i) <<< atTag "terminals" -< x
returnA -< Sentence { sid = i, terminals = ts }
...
getTerminal sid = atTag "t" >>>
proc x -> do
i <- getAttrValue "id" -< x
lem <- getAttrValue "lemma" -< x
returnA -< Terminal { lemma = lem, tid = nid i }
where
nid x = fromMaybe x (stripPrefix (sid ++ "_") x)
That is, i contains the value that I would like to pass to getTerminal.
Using
-<<instead of-<makes local bindings available to the arrow:Note that
-<<is implemented in terms ofappfromArrowApply. For instance, syntactical awkwardness aside, its occurrence above could be replaced with:The relevant arrows of hxt are instances of
ArrowApply, so-<<can be used with them.