Lennart Augustsson gave a nice example of how to define enums without having to maintain the forward as well as reverse transformations here [1]. Applying that to your problem:

> instance Enum STH where
>    fromEnum = fromJust . flip lookup table
>    toEnum = fromJust . flip lookup (map swap table)
> table = [(A, 1), (B, 66), (C, 111)]

And then you can use the code I gave in the previous reply to generate the Serialize instance. I suppose this is better looking, but you may want to check the efficiency since it requires a lookup (but it's a super tiny table so it might not be all that bad). You can generate similar code with Template Haskell, eliding the lookup. 

[1] http://stackoverflow.com/questions/6000511/better-way-to-define-an-enum-in-haskell

On Tue, Apr 26, 2016 at 1:40 PM, Magicloud Magiclouds <magicloud.magiclouds@gmail.com> wrote:
OK. So my understanding is there is no better (good-looking) code. Thank you all.
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe


--
Rahul Muttineni