Scala Applicative Composition Example

This is a continuation of my old questions :

I know that monads are not compound, i.e. if M1[_]they M2[_]are monads M2[M1[_]], they are not necessarily monads . For example, List[Int]they Option[Int]are monads, but Option[List[Int]]it is not automatically a monad, so I need to monad transformeruse it as a monad (as in here )

I know that applicative functors are compound. I think this means that if A1[_]they A2[_]are applicative, then A2[A1[_]]it is always applicative. Is it correct?

Could you give an example of such a composition when A1there is Listalso A2is Option? Could you give an example of other appeals made?

+4
source share
1 answer

I have added some examples to the source of scalas that are relevant. I have added examples of using composite instances of Apply (Apply is Applicative without the point method):

https://github.com/scalaz/scalaz/blob/series/7.2.x/example/src/main/scala/scalaz/example/ApplyUsage.scala#L132-L147

but yes, for anyone M1[_]for whom we have Applicative[M1]and M2[_]for which we have Applicative[M2], it M1[M2[_]]is applicative, and you can get an applicative instance withApplicative[M1] compose Applicative[M2]

+1

All Articles