Skip to content

Making toList a member of Foldable

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.

Trac metadata
Trac field Value
Version 6.12.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component libraries/base
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information