[Haskell-cafe] Odd list comprehension behaviour

Richard A. O'Keefe ok at cs.otago.ac.nz
Mon Mar 21 00:22:20 UTC 2016


Arithmetic progressions make *sense* for anything that has "+",
whether or not it also has "<".  For my Smalltalk system, I ended
up with a GenericInterval class with a creation method
    new: size from: start by: delta.

With *that* interface, a delta of zero is perfectly harmless.
     GenericInterval new: 4 from: 6 by: 0
is (6 6 6 6) and of course
     GenericInterval new: 1 from: 6 by: 0
is (6) because the new: argument *says* there is to be 1 element.

I understand why class Enum doesn't have this kind of interface.
Basically, we want to compute [delta*n + start | n <- [0..size-1]]
where in cases like duration*n+timestamp delta and start are not
the same type.

But let's face it, all that means is that if we want this kind of thing,
all we have to do is roll our own arithmetic progression functions.

Enum has other problems, like its coupling to Int.  I find it odd
that [1%1,9%8..2%1] works usefully even though
fromEnum (1%1) == fromEnum (9%8) == 1.  Sensible, just odd.






More information about the Haskell-Cafe mailing list