lens
引数を持ち、 type の 2 つの適用効果をmconcat
持つMaybe
モノイドになる関数を実装しようとしています(->) 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’