[英]How to add applicative effects to a monoid?
How can I change following code so that each element in Maybe
monoid element takes also two arguments (so it would become "double" reader applicative)? 如何更改下面的代码,以便
Maybe
在monoid元素中的每个元素也都带有两个参数(因此它将成为适用于“双重”读者的)?
g :: (Monoid a, IsString a) => [Maybe a] -> Maybe a
g = foldr (<>) (Just "")
So that result would be of type: 因此,结果将是以下类型:
g2 :: (Monoid a, IsString a) => [b -> c -> Maybe a] -> b -> c -> Maybe a
I guess I could lift <>
twice: 我想我可以两次提起
<>
:
> :t (liftA2 $ liftA2 (<>))
(liftA2 $ liftA2 (<>))
:: (Monoid c, Applicative f1, Applicative f) =>
f (f1 c) -> f (f1 c) -> f (f1 c)
But I'm stuck trying to compose it with foldr
to get the type signature I want. 但是我一直试图用
foldr
组合起来以获得我想要的类型签名。
这就是我会做的
g2 x y = g $ ($ y) <$> ($ x) <$> theList
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.