5

Where is the implicit conversion from a scala.collection.Traversable[A] to a scalaz.Foldable[A] defined in Scalaz 7.x? The standard import

import scalaz._
import Scalaz._

does not include it.

There used to be an implicit def TraversableFoldable[]... defined in scalaz/Foldable.scala, but

Relevant implicits used to be defined in scalaz/Foldable.scala, but have been moved into

scalaz.std.list
scalaz.std.iterable
...

scalaz.std.traversable does not exist, though. Perhaps this is an accidental omission?

FWIW, scalaz.std.list is included by the standard import, so a List[A] converts to a Foldable[A]. scalaz.std.iterable is not in the standard import and must be explicitly imported.to convert Iterable[A] to Foldable[A] implicitly.

David B.
  • 5,700
  • 5
  • 31
  • 52
  • Let me Github that for you: https://github.com/scalaz/scalaz/search?q=Foldable&ref=cmdform – wheaties Dec 22 '13 at 22:38
  • @wheaties I did that search before posting! Really! I didn't find anything useful---I'm hopeful someone knows enough to tell me either what replaced TraversableFoldable or that its omission is a bug. – David B. Dec 22 '13 at 22:48
  • Is Traversable not a `Semigroup`? Take a look to find out where the implicit from `Semigroup` to `Traversable` is found. That could be the issue. That or try to use the more general `TraversableLike[A, Repr]` where you bound `Repr : SemiGroup`. – wheaties Dec 22 '13 at 22:56
  • Why is `Semigroup` relevant here? – David B. Dec 22 '13 at 23:23
  • `Semigroup` has an implicit conversion to `Foldable`. – wheaties Dec 22 '13 at 23:42
  • 1
    Are you sure `Semigroup` has an implicit conversion to `Foldable`? Semigroups aren't naturally enumerable unless equipped with a generator. Here, `Semigroup[A]` is just endowing the type `A` with a binary operation `(A,A) -> A`, witnessing that `A` is a semigroup under that operation. There's no requirement in `Semigroup[A]` that a generator exist. – David B. Dec 23 '13 at 00:24
  • 1
    See for example [this answer](http://stackoverflow.com/a/15624788/334519) or [this mailing list thread](https://groups.google.com/forum/?fromgroups=#!searchin/scalaz/Seq/scalaz/Deaec1H11W4/gYFSquXjTzYJ) for some discussion of the closely related question of why there isn't a `Traverse` instance for `Seq` (which is even lower in the inheritance hierarchy). In short there's a kind of impedence mismatch between the way the standard collections library relies so heavily on subtyping and the abstractions used in Scalaz. – Travis Brown Dec 23 '13 at 13:27
  • @TravisBrown Interesting. Does prioritized implicits not solve this issue (e.g., the Seq -> Traverse implicit would have lower priority than the List -> Traverse implicit)? – David B. Dec 24 '13 at 00:01

0 Answers0