简体   繁体   中英

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)?

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.

这就是我会做的

g2 x y = g $ ($ y) <$> ($ x) <$> theList

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM