#3324: Add Foldable and Traversable instances for ((,) a)
------------------------------+---------------------------------------------
Reporter: YitzGale | Owner:
Type: proposal | Status: new
Priority: normal | Milestone:
Component: libraries/base | Version: 6.11
Severity: normal | Resolution:
Keywords: | Testcase:
Os: Unknown/Multiple | Architecture: Unknown/Multiple
------------------------------+---------------------------------------------
Comment (by LouisWasserman):
"The other is to fix the documentation for the functions fmapDefault and
foldMapDefault in Data.Traversable. Contrary to what is stated, these
cannot be used as methods in superclasses, since the superclasses must
already exist before these functions can be defined."
I don't think this is correct. Here is a sample usage of fmapDefault in
Data.Sequence (which definitely compiles):
{{{
instance Functor ViewL where
fmap = fmapDefault
instance Foldable ViewL where
foldMap = foldMapDefault
instance Traversable ViewL where
traverse _ EmptyL = pure EmptyL
traverse f (x :< xs) = (:<) <$> f x <*> traverse f xs
}}}
This is exactly what I expected from the original documentation.
What actually happens is that, in the case of the Functor instance, the
Functor instance -- specifically, fmapDefault -- is defined in terms of
the Traversable instance, and the Traversable instance depends on the
Functor instance. This sets up a legal recursion.
The following, in contrast, would not be legal:
{{{
data Foo a b = ...
instance Traversable (Foo a) => Functor (Foo a) where
fmap = fmapDefault
instance Traversable (Foo a) where
...
}}}
This would have set up a loop of dependencies, but in the first example,
the key is that the presence of the Functor instance (combined with the
Traversable instance) implies that fmapDefault is defined, and is
therefore legal.
I hope I'm making sense, but as I read it, the original documentation was
correct.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/3324#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs