I'm trying to refactor my function by giving it a lens argument (from the xml-lens
package). I'm missing something about type quantifiers. What is going on here?
*Main> let z name = listToMaybe $ pom ^.. root ./ ell name . text
*Main> :t z
z :: Text -> Maybe Text
*Main> let z name l = listToMaybe $ pom ^.. l ./ ell name . text
<interactive>:13:38:
Couldn't match expected type ‘(Element -> f Element)
-> Document -> f Document’
with actual type ‘t’
because type variable ‘f’ would escape its scope
This (rigid, skolem) type variable is bound by
a type expected by the context:
Applicative f => (Element -> f Element) -> Document -> f Document
at <interactive>:13:38-57
Relevant bindings include
l :: t (bound at <interactive>:13:12)
z :: Text -> t -> Maybe Text (bound at <interactive>:13:5)
In the first argument of ‘(./)’, namely ‘l’
In the second argument of ‘(^..)’, namely ‘l ./ ell name . text’
What is interesting, this signature works.
textFrom :: Text -> Document -> Lens' Document Element -> Maybe Text
textFrom name pom ln = listToMaybe $ pom ^.. ln ./ ell name . text
pom
,ell
,name
…? Did you write./
yourself or do you usexml-lens
? – Allanallanaxml-lens
package. – Toadflax