correction of the documentation for Traversable

Henning Thielemann lemming at henning-thielemann.de
Tue Apr 9 10:54:09 CEST 2013


On Tue, 9 Apr 2013, Petr Pudlák wrote:

> Dear haskellers,
> 
> I propose a correction to the documentation for Traversable. Currently it says:
> 
>   Minimal complete definition: traverse or sequenceA. 
> 
> This is not (completely) correct, it should be:
> 
>   Minimal complete definition:
>     - traverse or
>     - sequenceA with fmap.
> 
> What happened to me: I defined a Traversable instance with just sequenceA and used fmapDefault and
> foldMapDefault to define instances of Functor and Foldable. This resulted in an infinite loop. This is
> because traverse is defined using sequenceA and fmap, but fmapDefault is defined using traverse. So it's not
> enough to define sequenceA and use the default implementations for the rest, one also has to define fmap
> explicitly.

That's right. I think I also stumbled about it, but became curious how 
fmap can be implemented in terms of only sequenceA. Then I saw that 
fmapDefault is implemented in terms of 'traverse', where the default 
implementation of 'traverse' calls fmap and sequenceA.

Thus, if I want to define Functor, Foldable and Traversable instances with 
minimal effort, then I implement only traversable.


More information about the Libraries mailing list