[Haskell-cafe] Having trouble with instance context

Stephen Tetley stephen.tetley at gmail.com
Wed Feb 23 16:53:55 CET 2011


On 23 February 2011 15:40, Kurt Stutsman <kstutsman at gmail.com> 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.



More information about the Haskell-Cafe mailing list