[Haskell-cafe] Parsing different types, same typeclass
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
| "(A " `isPrefixOf` str = Left $ read str
| "(B " `isPrefixOf` str = Right $ read str
parseAction :: String -> Int
| "(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