#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 YitzGale):

 As noted by Ross Paterson on the libraries list: yes, you are correct,
 I was wrong. Except that it should be noted that using fmapDefault will
 only
 work if an explicit implementation was provided for traverse,
 otherwise infinite recursion will result.

 The thread is here:
 http://www.haskell.org/pipermail/libraries/2009-June/011991.html

 I will paste below my next attempt that I posted to the list
 in reply to Ross. The ideas are:

  * to note the requirement of a traverse implementation
  * to make explicit what we mean by using these functions to create
 Functor and Foldable instances
  * to note more clearly the other use of the two default functions: to
 test the consistency of a Traversable instance against the
 Foldable and Functor instances.

 Of course another option would be to keep it simple -
 keep the original, with just an added note about the
 requirement of an explicit traverse.

 Here's the new proposal that I wrote
 in my reply to Ross:

 In the documentation for class Traversable, change
 (`fmapDefault`) to (see `fmapDefault`), similarly
 for foldMapDefault.

 Documentation for fmapDefault:

 {{{
 -- | This function should be equivalent to `fmap` in
 -- the `Functor` superclass instance. If you do not
 -- already have a `Functor` instance, you can use
 -- this function to define one:
 --
 -- > instance Functor T where
 -- >   fmap = fmapDefault
 --
 -- Note, however, that this will lead to infinite
 -- recursion if you did not provide an explicit
 -- implementation of the `traverse` method.
 }}}

 Documentation for foldMapDefault:

 {{{
 -- This function should be equivalent to `foldMap` in
 -- the `Foldable` superclass instance. If you do not
 -- already have a `Foldable` instance, you
 -- can use this function to define one:
 --
 -- > instance Foldable T where
 -- >   foldMap = foldMapDefault
 }}}

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/3324#comment:2>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to