Re:Python's sad, unimaginative Enum
by tomp on Saturday May 11, 2013 @01:53PM
(#5691390)
But sometimes you only need enums (which are, arguably, a subcategory of ADTs). E.g. playing card suits, true/false, ...
[ Parent
| on HN ]
Not just arguably--that's exactly what they are. E.g., in Haskell:
data Suit = Spades
| Hearts
| Clubs
| Diamonds deriving (Show, Eq, Bounded, Enum)
this creates a type that acts exactly like an enum. With the added benefit of having a well-defined string representation and maxBound/minBound constants for free.True and false work fine as singleton subclasses of the abstract class Boolean; see Smalltalk.
What prevents me from making a third subclass, Undetermined?
ADTs and enums are meant to prevent this.