[Haskell-cafe] Parsing different types, same typeclass
"José A. Lopes"
jose.lopes at ist.utl.pt
Sun Nov 18 01:32:22 CET 2012
Hey Stephen,
Thank you for the reply!
Can you elaborate on how I can use existentials?
I always up for learning new (Haskell) stuff :)
Cheers,
José
On 18-11-2012 00:19, Stephen Tetley wrote:
> 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.
--
José António Branquinho de Oliveira Lopes
Instituto Superior Técnico
Technical University of Lisbon
More information about the Haskell-Cafe
mailing list