On 19/05/2010, at 20:36, Ivan Lazar Miljenovic wrote:

> Roman Leshchinskiy <r...@cse.unsw.edu.au> writes:
>> Personally, I consider the Enum class itself to be broken.
> 
> Oh?  In what sense?

Firstly, the enumFrom* family of functions shouldn't be methods and the class 
itself should provide enough facilities for implementing them generically. GHC, 
for instance, specialises them for all primitive numeric types just to get 
foldr/build fusion to work. That shouldn't be necessary and doesn't help with 
overloaded code anyway. For instance, this generates an intermediate list:

foo :: Enum a => a -> a -> [Int]
foo a b = [fromEnum x | x <- [a..b]]

It's even worse when you want to implement similar functionality for other data 
structures. In vector, I basically had to duplicate all those specialisations 
to get decent performance. The generic case is horribly inefficient:

enumFromTo x y = fromList [x .. y]

There is no other sensible definition.

Secondly, it should be possible to compute the length and the nth element of 
[a..b] in constant time. At the moment, it's impossible to distribute [a..b] 
efficiently across multiple threads - you have to generate the entire list 
first and then split it into chunks. It's completely unclear to me what [:a .. 
b:] should mean in DPH, for instance.

So basically, Enum only provides enough functionality to desugar [a..b] and 
friends and even here, it doesn't interact well with fusion. Of course, these 
concerns weren't relevant back when the class was designed. But it is really 
broken now, IMO.

Roman


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to