ocramz / xeno

Fast Haskell XML parser
Other
120 stars 33 forks source link

Update to documentaton to working examples #39

Closed jcornaz closed 4 years ago

jcornaz commented 4 years ago

Hello,

If I run the example from the documentation: parse "<p key='val' x=\"foo\" k=\"\"><a><hr/>hi</a><b>sup</b>hi</p>"

II get:

error:
    • Couldn't match expected type ‘Data.ByteString.Internal.ByteString’
                  with actual type ‘[Char]’
    • In the first argument of ‘parse’, namely
        ‘"<p key='val' x=\"foo\" k=\"\"><a><hr/>hi</a><b>sup</b>hi</p>"’
      In the expression:
        parse
          "<p key='val' x=\"foo\" k=\"\"><a><hr/>hi</a><b>sup</b>hi</p>"
      In an equation for ‘it’:
          it
            = parse
                "<p key='val' x=\"foo\" k=\"\"><a><hr/>hi</a><b>sup</b>hi</p>"

Obviously the documentation uses String where in fact ByteString are required.

Can you please update the documentation?

By the way, can you take the opportunity to document the rationale behind using ByteString rather than Text? As far as I know XML documents are textuals, not binary.

ocramz commented 4 years ago

Hi @jcornaz , thank you for raising this (the documentation should be clearer), but it also has an easy fix, i.e. setting the OverloadedStrings language extension. In GHCi, you can do it with the :set macro

> :set -XOverloadedStrings

The decision to use ByteStrings was due I think to the fact that much XML is exchanged as payloads of HTTP responses, or parsed from file. Converting to Text or String in those settings incurs extra cost.