我正在尝试实现一个函数,该函数有一个lens
参数,并且将mconcat
是一个Maybe
具有 type 的两个应用效果的 monoid (->) r
。我可能缺少一些基础知识,因此对分解此问题的任何帮助表示赞赏。
我想编写避免传递相同参数的“用户”代码,如下所示:
z pom root [(textFrom "groupId"), (textFrom "artifactId"), (textFrom "version")]
textFrom :: Text -> Document -> Lens' Document Element -> Maybe Text
textFrom name pom ln = listToMaybe $ pom ^.. ln ./ ell name . text
这是我尝试过的。无镜头概念:
Prelude Data.Monoid Control.Applicative> let f a b = Just $ show (a+1) ++ b
Prelude Data.Monoid Control.Applicative> let z a b xs = mconcat $ ($ b) <$> ($ a) <$> xs
Prelude Data.Monoid Control.Applicative> z 3 "x" [f,f]
Just "4x4x"
带镜头:
z :: (forall f. Functor f, Monoid b) => Document -> ((Element -> f Element) -> Document -> f Document) -> [Document -> ((Element -> f Element) -> Document -> f Document) -> b] -> b
z pom ln xs = mconcat $ ($ ln) <$> ($ pom) <$> xs
但它无法编译:
Couldn't match expected type ‘[a0
-> Document
-> [Document
-> ((Element -> f Element) -> Document -> f Document) -> b]
-> b]’
with actual type ‘(Element -> f Element) -> Document -> f Document’
Relevant bindings include
xs :: (Element -> f Element) -> Document -> f Document
(bound at Main.hs:27:10)
z :: (forall (f1 :: * -> *). Functor f1)
-> Monoid b =>
Document
-> ((Element -> f Element) -> Document -> f Document)
-> [Document
-> ((Element -> f Element) -> Document -> f Document) -> b]
-> b
(bound at Main.hs:27:1)
Probable cause: ‘xs’ is applied to too few arguments
In the second argument of ‘(<$>)’, namely ‘xs’
In the second argument of ‘($)’, namely ‘($ ln) <$> ($ pom) <$> xs’