correction of the documentation for Traversable
Ross Paterson
R.Paterson at city.ac.uk
Tue Apr 9 14:43:30 CEST 2013
On Tue, Apr 09, 2013 at 10:00:56AM +0200, Petr Pudlák wrote:
> 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.
I was about to say that the right place to say this would be the
documentation for fmapDefault, because "Minimal complete definition"
lists methods of the class being defined, and the real problem here
is in the Functor instance. But I see it's already there:
-- | This function may be used as a value for `fmap` in a `Functor`
-- instance, provided that 'traverse' is defined. (Using
-- `fmapDefault` with a `Traversable` instance defined only by
-- 'sequenceA' will result in infinite recursion.)
fmapDefault :: Traversable t => (a -> b) -> t a -> t b
More information about the Libraries
mailing list