[Haskell-cafe] How to tie knots in XML-style data structures

Simon Jakobi simon.jakobi at googlemail.com
Mon Jan 2 14:27:27 UTC 2017

Hi Auke,

I have admittedly only skimmed your email, but your problem reminds me
of a talk by Joachim Breitner.

A German transcript of the talk is available here:

I hope this is useful to you!

2017-01-02 15:08 GMT+01:00 Auke Booij <auke at tulcod.com>:
> I am reading an XML file, where some nodes have attributes that refer
> to other nodes. For example:
> <blah name="first" type="5">
>  <yada blah="second"></yada>
> </blah>
> <blah name="second" type="3">
> </blah>
> Here, the point is that the inner <yada> refers to a <blah> that is
> not its parent by means of a "blah" attribute. But there might also be
> a mistake in the XML file, which I would then want to report: the
> inner <yada> might refer to a <blah> which does not exist.
> Using an XML parsing library, this XML file can easily be read into a
> data type such as the following:
> data Blah = Blah {blahName :: String, blahType :: Int, blahYadas :: [Yada]}
> data Yada = Yada {yadaBlah :: String}
> But for my application, it is useful to have the Yadas refer back to
> actual Blahs, instead of just their name Strings. So I'd like to parse
> the XML into the following data structure:
> data Blah' = Blah' {blah'Name :: String, blah'Type :: Int, blah'Yadas
> :: [Yada']}
> data Yada' = Yada' {yada'Blah :: Blah}
> (the only change is the type of yada'Bla from String to Blah)
> 1. How can I write a function that takes a Blah, and outputs a Blah',
> and reports a nice error when there is no <blah> with the name
> specified in the <yada>? Can it be done at all without using partial
> functions like fromJust (when using Maybe to "report" errors)?
> 2. Is there a better way to define the types Blah, Yada, Blah' and
> Yada' (e.g. with less repetition)? After all, all I'm changing is the
> type of one field, but I end up having to redefine all my types.
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.

More information about the Haskell-Cafe mailing list