You may also look at Data.Dynamic / Data.Typeable. It may not work really well, 
depending on how you defined A and B. In GHC, it should work with any type 
produced with the haskell 98 use of the keyword "data", though.

This is the "canonical" solution to cope with the GHC API returning values of 
arbitrary type.

Good luck,
Pierre

El 02/09/2010, a las 16:31, Andrew U. Frank escribió:

> I have a user input (string) and need to select one of two types.
> depending what the input is. is this possible? 
> 
> data A
> data B 
> 
> data X n = X String
> 
> op :: String -> X n
> op "a" = X "a" :: X A
> op "b" = X "b" :: X B
> 
> this does obviously not compile. is there a way to achieve that the type
> X A is produced when the input is "a" and X B when the input is "b"?
> 
> thank you for help!
> andrew
> 
> 
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to