arosien/scalaz-cheatsheets

Include constraints on Traverse and Foldable primitives

Closed this issue · 5 comments

I understand your reasons for leaving out the Applicative and Monoid constraints when defining their primitives, but they're essential to the nature of those abstractions. For example, the only change when going to Traverse1 and Foldable1 is to change those constraints to Apply and Semigroup, which says worlds about what those are.

Excellent point. I'll figure out a way to note that, either directly or via footnote. Thanks.

@S11001001, how do these footnotes sound?

Traverse requires that the target type constructor G have an implicit Applicative instance available; that is, an implicit Applicative[G] must be in scope.

Foldable requires that the target type B have an implicit Monoid instance available; that is, an implicit Monoid[B] must be in scope. Informally, you're folding something up, so you need to know how to squash things together!

Your commentary on Foldable is sufficiently helpful to inspire me to say that the line on Traverse isn't helpful enough :)

You might say that Applicative means that zero or more G-effects can be combined into one.

"Informally, traversing a structure maps each value to some effect, which are combined into a single effect that produces a value having the original structure. For example, by transforming every A of a List[A] into a Future[B], the traversal would return a Future[List[B]]."

Nice.