Thanks much for the answers, Conor. They all make sense to me, particularly about the typical information discarding in Foldable.
Regards, - Conal
On 3 Jan 2012, at 23:12, Conal Elliott wrote:
I wanted a Traversable instance for pairing, so I defined one:> instance Traversable ((,) o) where
> sequenceA (o,fa) = (o,) <$> fa
That looks right. Of course, we should really have a BiTraversable
class of which (,) is an instance.The best (upto efficiency considerations) is always
However, Foldable is a superclass of Traversable, so I get an error message:
Could not deduce (Foldable ((,) o)) from the context ()
arising from the superclasses of an instance declaration
The best I've thought of is the following:
> instance Foldable ((,) o) where
> fold (_,m) = m
foldMap = foldMapDefault
instance Foldable ((,) o) where
which amounts to what you chose.
SHE makes this a default superclass instance.But these folds always do discard information, discarding the shape
However, I don't like how it discards information.
information and accumulating over the contents. For ((,) o), seen as
a functor, the first component is shape information and the second is
the content.Because the constant-monoid Applicative makes every Traversable
Some questions:
* Why is Foldable a superclass of Traversable?
Foldable in a uniform way.Yes, the one you chose.
* Is there a good choice of a Foldable instance of ((,) o)?
Nope. It's the Traversable instance which picks out exactly the
* Are there any other problems with the Traversable instance above (besides foldability)?
contents that correspond to the elements abstracted by the Functor.
All the best
Conor