[Haskell-cafe] instance Enum Double considered not entirely great?
Roman Leshchinskiy
rl at cse.unsw.edu.au
Wed Sep 28 23:56:28 CEST 2011
On 25/09/2011, at 18:20, Chris Smith wrote:
> class Ord a => Range a where
> rangeFromTo :: a -> a -> [a] -- subsumes Ix.range / Enum.enumFromTo
> rangeFromThenTo :: a -> a -> a -> [a]
> inRange :: (a, a) -> a -> Bool
> -- Does have instances for Float/Double. List ranges desugar to this.
> -- Also has instances for tuples
>
> class Range a => InfiniteRange a where -- [1]
> rangeFrom :: a -> [a]
> rangeFromThen :: a -> a -> [a]
> -- Has instances for Float/Double
> -- No instances for tuples
I realise I'm slightly late to the discussion but IMO, the rangeFrom* (or enumFrom*) functions shouldn't be methods. Rather, a redesign of Enum should ensure that they can be defined generically for all types. The rationale is that other data structures (like arrays) want to provide similar functions without having to go through lists.
Roman
More information about the Haskell-Cafe
mailing list