
Stephen Tetley wrote:
On 23 February 2011 15:40, Kurt Stutsman
wrote: instance Enum e => Serializable e where get mask = {- convert mask to Int and then to a BitSet -} put bitset = {- convert BitSet to Int and then to String -}
I looks like all you need is for objects to be enumerable, i.e have instances of Enum. So instead of the above class, can you manage with these two functions?
get :: Enum e => e -> Int
put :: BitSet -> String
Type classes give you type-based dispatch - *but* they are overkill if you don't actually need type-base dispatch.
I need to support non-enumerable data types as well. That's why I wanted the Serializable class. For those non-enumerable types, I can create a custom instance of the Serializable class. But for Enums, I will always do the same thing, so implementing Serializable for all Enum types is really overkill.