[Haskell-beginners] comment on this debugging trick?

Stephen Tetley stephen.tetley at gmail.com
Sun Nov 29 00:31:54 UTC 2015


Hi Jeffrey

The example you linked to is a JSON parser written with Parsec - it
takes an input stream of characters and returns a JSON tree. To go
from "uni-typed" JSON to Haskell data represented by your domain
datatypes you have to do further conversion. This conversion is from
"tree to tree" rather than "from input stream to tree".

If the correspondence between the JSON (or XML) is one-to-one you can
do a fairly mechanical deserialization (I think some of the libraries
already have Template Haskell processors for this). In Dennis's case
he wants to go from a very large XML representation to deal with a
more manageable subset in Haskell and believes that the input he works
with always belongs to the manageable subset. To get from MusicXML's
large tree - represented again by a uni-typed tree in XML.Light -
parser combinators provide a fine API for the job but the internal
machinary needs to be able to traverse a tree (descend child nodes,
climb back out on failure etc.) rather than consume an input stream.

On 28 November 2015 at 17:58, Jeffrey Brown <jeffbrown.the at gmail.com> wrote:
>>  (Parsec, Attoparsec, ...) can't
>> be used with XML.Light because their mechanics are consuming
>> an input stream whereas processing XML (or JSON) is
>> moving a cursor through a tree
>
> Stephen, the "consuming an input vs. moving a cursor through a tree"
> distinction you're drawing is unclear to me. Can you elaborate, or provide
> references?
>
> Also, Text.JSON.Parsec [1] would appear to be a counterexample to your
> claim.
>
> [1]
> https://hackage.haskell.org/package/json-0.9.1/docs/Text-JSON-Parsec.html


More information about the Beginners mailing list