I'm trying to implement some kind of message parser in Haskell, so I decided to use types for message types, not constructors:

data DebugMsg  = DebugMsg String
data UpdateMsg = UpdateMsg [String]

.. and so on. I belive it is more useful to me, because I can define typeclass, say, Msg for message with all information/parsers/actions related to this message. But I have problem here. When I try to write parsing function using case:

parseMsg :: (Msg a) => Int -> Get a
parseMsg code = 
    case code of
        1 -> (parse :: Get DebugMsg)
        2 -> (parse :: Get UpdateMsg)

..type of case result should be same in all branches. Is there any solution? And does it even possible specifiy only typeclass for function result and expect it to be fully polymorphic?

Edit
Report