[GHC] #4024: Making toList a member of Foldable

GHC cvs-ghc at haskell.org
Tue Apr 27 16:35:34 EDT 2010


#4024: Making toList a member of Foldable
---------------------------------+------------------------------------------
    Reporter:  Eelis-            |       Owner:                  
        Type:  proposal          |      Status:  new             
    Priority:  normal            |   Component:  libraries/base  
     Version:  6.12.1            |    Keywords:  Foldable, toList
          Os:  Unknown/Multiple  |    Testcase:                  
Architecture:  Unknown/Multiple  |     Failure:  None/Unknown    
---------------------------------+------------------------------------------
 The toList function in Data.Foldable is currently not a member of the
 Foldable type class, and is consequently not specializable.

 This is a great shame, because for data types such as [a] and

   data NonEmptyList a = NonEmptyList a [a]

 conversion to list can trivially be implemented in O(1) instead of the
 generic toList's O(n).

 In other words, any code that directly or indirectly uses Foldable's
 toList on values of these types needlessly performs O(n) conversions where
 O(1) conversions are available.

 Fortunately, the solution is very simple: just make toList a member of the
 Foldable type class.

 I'm attaching a patch that does just this.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4024>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the Glasgow-haskell-bugs mailing list