
Hi all, i'm having a bit of difficulty using GHCi to try out HXT. i brought the Text.XML.HXT.Arrow module into scope using :m. Then i entered: let contact = mkelem "stream:stream" [ sattr "xmlns:stream" "http://etherx.jabber.org/streams", sattr "xmlns" "jabber:client", sattr "to" "livejournal.com" ] [] and got the error message: <interactive>:1:14: Ambiguous type variable `a' in the constraint: `ArrowXml a' arising from use of `mkelem' at <interactive>:1:14-19 Probable fix: add a type signature that fixes these type variable(s) The type signature of mkelem is mkelem :: (ArrowXml a) => String -> [a n XmlTree] -> [a n XmlTree] -> a n XmlTree So then i modified it to: let contact = mkelem "stream:stream" [ sattr "xmlns:stream" "http://etherx.jabber.org/streams", sattr "xmlns" "jabber:client", sattr "to" "livejournal.com" ] [] :: ArrowXml a => a XmlTree XmlTree And got: <interactive>:1:14: Ambiguous type variable `a' in the constraint: `ArrowXml a' arising from instantiating a type signature at <interactive>:1:14-194 Probable fix: add a type signature that fixes these type variable(s) i don't understand why i need to specify type signatures when they should already be in scope? And if i /do/ need to specify the type signatures for some reason, how do i do so in a manner that works? Any help much appreciated! Alexis.

On Tuesday 28 November 2006 20:50, Alexis Hazell wrote:
let contact = mkelem "stream:stream" [ sattr "xmlns:stream" "http://etherx.jabber.org/streams", sattr "xmlns" "jabber:client", sattr "to" "livejournal.com" ] [] :: ArrowXml a => a XmlTree XmlTree
And got:
<interactive>:1:14: Ambiguous type variable `a' in the constraint: `ArrowXml a' arising from instantiating a type signature at <interactive>:1:14-194 Probable fix: add a type signature that fixes these type variable(s)
i don't understand why i need to specify type signatures when they should already be in scope?
Is this a result of the monomorphism restriction?
And if i /do/ need to specify the type signatures for some reason, how do i do so in a manner that works?
You need to add a type signature that specifies a specific arrow data type 'a' that is an instance of ArrowXml. There are many instances of ArrowXml provided in HXT, eg LA, IOSArrow, IOSLArrow, etc so try something like: let contact = mkelem "stream:stream" [ sattr "xmlns:stream" "http://etherx.jabber.org/streams", sattr "xmlns" "jabber:client", sattr "to" "livejournal.com" ] [] :: IOSArrow XmlTree XmlTree By the way, once you have the declaration of contact in a source file, and it is being used by a function in which the ArrowXml instance is not ambiguous eg: foo = runX contact the type checker will be able to infer the type and you don't have to include the type signature. Daniel

On Tue, 28 Nov 2006 07:43 pm, Daniel McAllansmith wrote:
On Tuesday 28 November 2006 20:50, Alexis Hazell wrote:
i don't understand why i need to specify type signatures when they should already be in scope?
Is this a result of the monomorphism restriction?
Er . . . . i hadn't heard of this until just now. So i'll have to do some reading on the matter. :-)
You need to add a type signature that specifies a specific arrow data type 'a' that is an instance of ArrowXml.
Ah! i see - thanks.
By the way, once you have the declaration of contact in a source file, and it is being used by a function in which the ArrowXml instance is not ambiguous eg:
foo = runX contact
the type checker will be able to infer the type and you don't have to include the type signature.
*nod* Thanks again for your help. :-) Alexis.
participants (2)
-
Alexis Hazell
-
Daniel McAllansmith