我试图通过给它一个镜头参数(来自xml-lens
包)来重构我的函数。我错过了关于类型量词的一些东西。这里发生了什么?
*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’
有趣的是,这个签名有效。
textFrom :: Text -> Document -> Lens' Document Element -> Maybe Text
textFrom name pom ln = listToMaybe $ pom ^.. ln ./ ell name . text