Repair to floating point enumerations?
Roman Leshchinskiy
rl at cse.unsw.edu.au
Fri Oct 17 08:06:44 EDT 2008
On 15/10/2008, at 20:41, Malcolm Wallace wrote:
> Phil proposes that, although retaining the instances of Enum for Float
> and Double, we simplify the definitions of the numericEnumFrom family:
>
> numericEnumFromThenTo :: (Fractional a, Ord a) => a -> a -> a ->
> [a]
> numericEnumFrom = iterate (+1)
> numericEnumFromThen n m = iterate (+(m-n)) n
> numericEnumFromTo n m = takeWhile (<= m) (numericEnumFrom n)
> numericEnumFromThenTo n m p = takeWhile (<= p) (numericEnumFromThen
> n m)
I'd like to raise the following two points in this context.
Firstly, an array library which attempts to provide reasonable
counterparts to the list functions would want to define array versions
of enumFromTo and enumFromThenTo. To be efficient, it must be able to
determine the expected number of elements reasonably fast (in constant
time).
Secondly, a parallel array library (such as the one provided by DPH)
also needs to be able to generate, say, the first half of the array on
one processor and the second half on another. This requires enumFromTo
to obey some form of the following law for some f and g:
enumFromTo m n = enumFromTo m (f m n) ++ enumFromTo (g m n) n
It might make sense to try to provide this for Float and Double for
the sake of consistency with future libraries. I'm not sure how easy
it is to do, though.
Roman
More information about the Haskell-prime
mailing list