The problem is in the expression
(xtext "some text" :
(xelem "hugo" (xattr "age" "24" <#>
xtext "thingy")))
The part after the :
(starting with xelem "hugo"
) is not a list. I good way to debug such type problems is using ghci. That's what I did in the first place, and the ghci quickly leads you in the right direction:
*Text.XML.Generator> :t xtext "some text" : xelem "hugo" (xattr "age" "24" <#> xtext "thingy")
<interactive>:1:21:
Couldn't match expected type `[Xml Elem]'
with actual type `Xml Elem'
In the return type of a call of `xelem'
In the second argument of `(:)', namely
`xelem "hugo" (xattr "age" "24" <#> xtext "thingy")'
In the expression:
xtext "some text"
: xelem "hugo" (xattr "age" "24" <#> xtext "thingy")
A good question is why GHC give's such a bad error message in the first place. The problem is that the result type of xelem
is overloaded, in fact xelem
has type n -> MkElemRes n c
. The instantiation for MkElemRes n c
you are trying to use in your example is indeed a function type, so this part of your example is correct. But in general MkElemRes n c
does not need to be a function type and that's why GHC complains about two arguments where it expects only one (namely one of type MkElemRes n c
).
Here are one solution to your original problem:
xelem "person" $
xelems [xtext "some text", xelem "hugo" (xattr "age" "24" <#> xtext "thingy")]
Here is an alternative solution:
xelem "person" $ xtext "some text" <> xelem "hugo" (xattr "age" "24" <#> xtext "thingy")