Opened 12 years ago

Last modified 2 years ago

#109 new task

split Enum into two typeclasses

Reported by: Owned by: none
Priority: normal Milestone:
Version: Keywords:
Cc: Meta Owner:
State: discussion Section: N/A or multiple
Related Tickets:

Description

The current uses of Enum are somewhat confusing — this is partially because of the name, but partially because two seperate interfaces are glued together. One provides Enumeration of all possible values and conversion to integers for binary storage, and the other provides sequences of values (usually arithmetic) (which [a..b], etc desugar to).

class Enum a where
    succ, pred :: a -> a
    toEnum     :: Int -> a
    fromEnum   :: a -> Int

instance Enum Integer
instance Enum Int
instance Enum Bool
instance Enum Ordering
instance Enum Word...
class ArithmeticSequence a where
    stepFrom        :: a -> [a]           -- [n..]
    stepFromThen    :: a -> a -> [a]      -- [n, n'..]
    stepFromTo      :: a -> a -> [a]      -- [n..m]
    stepFromThenTo  :: a -> a -> a -> [a] -- [n,n'..m]

instance ArithmeticSequence Integer
instance ArithmeticSequence Int
instance ArithmeticSequence Bool
instance ArithmeticSequence Ordering
instance ArithmeticSequence Float
instance ArithmeticSequence Double
instance ArithmeticSequence Rational
instance ArithmeticSequence Word...
...

Steppable may be a preferrable name.

pros:

  • Clearly divides two seperate uses, while keeping functionality.
  • Can re-introduce relationship between Ix and Enum?

cons:

  • Yet another typeclass.
  • Slightly misleading name, as non-arithmetic structures _should_ be supported. Also a bit long.
  • Automatically supporting such isn't trivial if they're not in Enum, though.

Change History (2)

comment:1 Changed 2 years ago by Herbert Valerio Riedel

Milestone:

moving non-milestoned many year old legacy tickets out of the way

comment:2 Changed 2 years ago by Herbert Valerio Riedel

Priority: minornormal

Set default priority (as this confuses Trac otherwise)

Note: See TracTickets for help on using tickets.