
27 Apr
2010
27 Apr
'10
11:12 a.m.
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 have attached a patch that does just this.