[Haskell-cafe] Parsing different types, same typeclass

Stephen Tetley stephen.tetley at gmail.com
Sun Nov 18 00:19:51 CET 2012

Being concrete, all you can do is:

parseAction :: String -> Either A B
parseAction str
    | "(A " `isPrefixOf` str = Left $ read str
    | "(B " `isPrefixOf` str = Right $ read str

parseAction :: String -> Int
parseAction str
    | "(A " `isPrefixOf` str = run $ (read str :: A)
    | "(B " `isPrefixOf` str = run $ (read str :: B)

As you can't return a polymorphic /a/ when you have typed the cases to A or B.

Being less concrete, no doubt you can use existentials, but at this
point I'd recommend you re-evaluate what you are trying to do.

More information about the Haskell-Cafe mailing list