Good day, question is rather noobish, but i stuck with it.
I decided to migrate from plain Strings to Text in my project and faced the problem, all strings in source yielded compilation errors after adding {-# LANGUAGE OverloadedStrings #-}, for example snippet like:
dropWhile (~/= "<li>") tags
now leads to
Ambiguous type variable
t' in the constraints:
Data.String.IsString t' arising from the literal"<li>"' at ParserOx.hs:93:42-47
TagRep t' arising from a use of `~=='
What could be wrong here ?
UPD:
And yes, all my functions have signatures, ex:
getContainer :: [Tag Text] -> [Tag Text]
getContainer tags =
h
where
(h:t) = sections (~== "<div id=\"itemscontainer\">") tags
The problem is that you have an ambiguous type with two constraints -- the isstring constraint given by overloaded strings, and the tagrep constraint used by tagsoup to allow you to use tags or strings interchangeably. So two methods of "overloading" strings (one in general, and one just for use in tagsoup's matchers) are running into one another and causing confusion. Either turn off overloaded strings in the offending file, or specify your strings as actual strings in the code (i.e. (~/= ("<li>"::String))
). Rather than inline type signatures, you can do the following to force types more quietly:
s :: String -> String
s = id
.... (~/= s "<li>") ...
One option is to define a wrapper around ~==
which pins down parts of the type. For example, you could define:
(~===) a b = a ~== (b :: String)
Then you can just write (~=== "<div id=\"itemscontainer\">")
with no further annotations at the use site.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With