3 ms·
But sometimes you only need enums (which are, arguably, a subcategory of ADTs). E.g. playing card suits, true/false, ...
by tomp 14y ago
But sometimes you only need enums (which are, arguably, a subcategory of ADTs). E.g. playing card suits, true/false, ...
- tikhonj 14y agoNot 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.
- gnaritas 14y agoTrue and false work fine as singleton subclasses of the abstract class Boolean; see Smalltalk.