Haskell xml-conduit without OverloadedStrings? -
every example have seen online of haskell's xml-conduit module uses overloadedstrings ghc extension (e.g. here). assume because text.xml.cursor.element
function has type name -> axis
. example, snippet not work without overloadedstrings:
{-# language overloadedstrings #-} import text.xml import text.xml.cursor import data.text (text) import data.text.read (decimal) import data.monoid (mconcat) main :: io () main = doc <- text.xml.readfile def "people2.xml" let cursor = fromdocument doc print $ cursor $// element "{http://example.com}person" >=> parseperson data person = person int text deriving show parseperson :: cursor -> [person] parseperson c = let name = c $/ element "{http://example.com}firstname" &/ content agetext = c $/ element "{http://example.com}age" &/ content case decimal $ mconcat agetext of right (age, "") -> [person age $ mconcat name] _ -> []
however, want write module more portable, i.e. without using extension. best way of doing this? doomed create text
value each string data.text.pack
, using text.xml.name
data constructor before passing result element
? or there easier way?
i'm afraid "easier way" -xoverloadedstrings. i'm afraid you're not going able meet portability goals while relying on xml-conduit, because makes liberal use of language extensions itself.
unless have specific alternative compiler targeting, might use -xoverloadedstrings, since xml-conduit explicitly designed support it.
Comments
Post a Comment